source: binary-improvements/CoppisAdditions/src/Commands/UnlockAll.cs@ 291

Last change on this file since 291 was 273, checked in by alloc, 9 years ago

fixes 8_10_13_1

File size: 3.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.IO;
4using UnityEngine;
5
6namespace CoppisAdditions.CustomCommands
7{
8 public class UnlockAll : ConsoleCmdAbstract
9 {
10 public override string GetDescription ()
11 {
12 return "unlock all secure loots, chests and doors for the current player.";
13 }
14
15 public override string GetHelp ()
16 {
17 return "Unlock all secure loots, chests and doors for the current player. After using this command you need to leave and reenter the game to take effect.";
18 }
19
20 public override string[] GetCommands ()
21 {
22 return new string[] { "unlockall" };
23 }
24
25 public override void Execute (List<string> _params, CommandSenderInfo _senderInfo)
26 {
27 try {
28 if (_senderInfo.RemoteClientInfo == null || _senderInfo.RemoteClientInfo.playerId == null || _senderInfo.RemoteClientInfo.playerId.Equals ("")) {
29 SdtdConsole.Instance.Output ("Unable to apply this command. You need be a player to execute it.");
30 return;
31 }
32 ClientInfo ci = ConsoleHelper.ParseParamIdOrName (_senderInfo.RemoteClientInfo.playerName);
33 ChunkClusterList chunklist = GameManager.Instance.World.ChunkClusters;
34 string SteamID = _senderInfo.RemoteClientInfo.playerId;
35 int lootsUnlocked = 0;
36 int doorsUnlocked = 0;
37 for (int i = 0; i < chunklist.Count; i++) {
38 ChunkCluster chunk = chunklist [i];
39 List<Chunk> clist = chunk.GetChunkArray ();
40 foreach (Chunk c in clist) {
41 DictionarySave<Vector3i, TileEntity> tiles = c.GetTileEntities ();
42 foreach (TileEntity tile in tiles.Values) {
43 TileEntityType type = tile.GetTileEntityType ();
44 try {
45 if (type.ToString ().Equals ("Campfile")) {
46 //TileEntityCampfire campfire = (TileEntityCampfire)tile;
47 //SdtdConsole.Instance.Output("campfire: " + );
48 } else if (type.ToString ().Equals ("Loot")) {
49 //TileEntityLootContainer loot = (TileEntityLootContainer) tile;
50
51 } else if (type.ToString ().Equals ("Forge")) {
52 //TileEntityForge forge = (TileEntityForge) tile;
53 } else if (type.ToString ().Equals ("SecureLoot")) {
54 TileEntitySecureLootContainer secureLoot = (TileEntitySecureLootContainer)tile;
55 //SdtdConsole.Instance.Output("secure loot ower: " + secureLoot.GetOwner());
56 List<string> users = secureLoot.GetUsers ();
57 if (!users.Contains (SteamID)) {
58 users.Add (SteamID);
59 lootsUnlocked = lootsUnlocked + 1;
60 }
61 } else if (type.ToString ().Equals ("SecureDoor")) {
62 TileEntitySecureDoor secureDoor = (TileEntitySecureDoor)tile;
63 List<string> users = secureDoor.GetUsers ();
64 if (!users.Contains (SteamID)) {
65 users.Add (SteamID);
66 doorsUnlocked = doorsUnlocked + 1;
67 }
68 }
69 } catch (Exception) {
70
71 }
72 }
73 }
74
75
76 if (ci != null) {
77 ci.SendPackage (new NetPackageChunkClusterInfo (chunk));
78 }
79 }
80 SdtdConsole.Instance.Output ("Secure Loots/Chest unlocked: " + lootsUnlocked);
81 SdtdConsole.Instance.Output ("Secure Doors unlocked: " + doorsUnlocked);
82 SdtdConsole.Instance.Output ("*Remember: you need to leave and enter again to apply this command on server`s map");
83 } catch (Exception e) {
84 Log.Out ("Error in UnlockAll.Run: " + e);
85 }
86
87 }
88 }
89}
Note: See TracBrowser for help on using the repository browser.