public static EntityPlayerLocal Adjust(EntityPlayerLocal _entityPlayerLocal, string _itemName, int _itemCount) { Log.Out("[SERVERTOOLS] Adjusting local player bag"); Log.Out(string.Format("[ST] _itemName = {0}, _itemCount = {1}", _itemName, _itemCount)); ItemValue _itemValue = new ItemValue(ItemClass.GetItem(_itemName).type, 1, 1, false, null, 1); if (_itemValue != null) { Log.Out("[SERVERTOOLS] _itemValue not null"); int _count = _itemCount; ItemStack[] bagSlots = _entityPlayerLocal.bag.GetSlots(); for (int i = 0; i < bagSlots.Length; i++) { Log.Out(string.Format("[ST] bagSlots[i].itemValue.GetItemOrBlockId() = {0}, _itemValue.GetItemOrBlockId() = {1}", bagSlots[i].itemValue.GetItemOrBlockId(), _itemValue.GetItemOrBlockId())); if (_count != 0 && !bagSlots[i].IsEmpty() && bagSlots[i].itemValue.GetItemOrBlockId() == _itemValue.GetItemOrBlockId()) { if (bagSlots[i].count <= _count) { int _newCount = _count - bagSlots[i].count; Log.Out(string.Format("[ST] _count = {0}, bagSlots[i].count = {1}, _newCount = {2}", _count, bagSlots[i].count, _newCount)); _count = _newCount; bagSlots[i] = ItemStack.Empty.Clone(); } else { int _newCount = _count - bagSlots[i].count; Log.Out(string.Format("[ST] _count = {0}, bagSlots[i].count = {1}, _newCount = {2}", _count, bagSlots[i].count, _newCount)); _count = 0; ItemStack _stack = new ItemStack(bagSlots[i].itemValue, _newCount); bagSlots[i] = _stack.Clone(); } } } _entityPlayerLocal.bag.SetSlots(bagSlots); Log.Out("[SERVERTOOLS] Completed adjustment"); } return(_entityPlayerLocal); }
public static void ChestToBankDeposit(ClientInfo _cInfo, string _amount) { ItemValue _itemValue = ItemClass.GetItem(Ingame_Coin, false); if (CoinCheck(_cInfo, _itemValue)) { int _value; if (int.TryParse(_amount, out _value)) { _itemValue = new ItemValue(ItemClass.GetItem(Ingame_Coin).type, 1, 1, false, null, 1); int _currencyToRemove = _value; int _currencyRemoved = 0; ChunkClusterList chunklist = GameManager.Instance.World.ChunkClusters; for (int i = 0; i < chunklist.Count; i++) { if (_currencyToRemove > 0) { ChunkCluster chunk = chunklist[i]; chunkArray = chunk.GetChunkArray(); foreach (Chunk _c in chunkArray) { tiles = _c.GetTileEntities(); foreach (TileEntity tile in tiles.dict.Values) { TileEntityType type = tile.GetTileEntityType(); if (type.ToString().Equals("SecureLoot")) { TileEntitySecureLootContainer SecureLoot = (TileEntitySecureLootContainer)tile; if (SecureLoot.IsUserAllowed(_cInfo.playerId) && !SecureLoot.IsUserAccessing()) { Vector3i vec3i = SecureLoot.ToWorldPos(); EntityPlayer _player = GameManager.Instance.World.Players.dict[_cInfo.entityId]; if ((vec3i.x - _player.position.x) * (vec3i.x - _player.position.x) + (vec3i.z - _player.position.z) * (vec3i.z - _player.position.z) <= 2.5 * 2.5) { ItemStack[] _items = SecureLoot.items; for (int j = 0; j < _items.Length; j++) { if (_currencyToRemove > 0) { if (!_items[j].IsEmpty() && _items[j].itemValue.GetItemOrBlockId() == _itemValue.GetItemOrBlockId()) { if (_items[j].count <= _currencyToRemove) { int _newCount = _currencyToRemove - _items[j].count; int _newCount2 = _currencyRemoved + _items[j].count; _currencyToRemove = _newCount; _currencyRemoved = _newCount2; _items[j] = ItemStack.Empty.Clone(); } else { int _newCount = _currencyRemoved + _currencyToRemove; int _newStackCount = _items[j].count - _currencyToRemove; _currencyToRemove = 0; _currencyRemoved = _newCount; _items[j] = new ItemStack(_itemValue, _newStackCount); break; } } } } } } } } } } } if (_currencyRemoved > 0) { if (Deposit_Fee_Percent > 0) { int _depositFeePercent = Deposit_Fee_Percent / 100; int _depositFee = (int)_currencyRemoved * _depositFeePercent; int _adjustedDeposit = _currencyRemoved - _depositFee; AddCoinsToBank(_cInfo.playerId, _adjustedDeposit); string _message = " deposited {Value} {Name} from the secure loot to your bank account. " + " {Percent}" + "% fee was applied."; _message = _message.Replace("{Value}", _value.ToString()); _message = _message.Replace("{Name}", Ingame_Coin); _message = _message.Replace("{Percent}", Deposit_Fee_Percent.ToString()); ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _message + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); using (StreamWriter sw = new StreamWriter(filepath, true)) { sw.WriteLine(string.Format("{0}: {1} has added {2} to their bank account from a secure loot.", DateTime.Now, _cInfo.playerName, _currencyRemoved)); sw.WriteLine(); sw.Flush(); sw.Close(); } using (StreamWriter sw = new StreamWriter(filepath, true)) { sw.WriteLine(string.Format("{0}: {1} has added {2} to their bank account from a secure loot.", DateTime.Now, _cInfo.playerName, _adjustedDeposit)); sw.WriteLine(); sw.Flush(); sw.Close(); } } else { AddCoinsToBank(_cInfo.playerId, _currencyRemoved); string _message = "Removed {Total} {Name} and deposited it to your bank. "; _message = _message.Replace("{Total}", _currencyRemoved.ToString()); _message = _message.Replace("{Name}", Ingame_Coin); ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _message + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); using (StreamWriter sw = new StreamWriter(filepath, true)) { sw.WriteLine(string.Format("{0}: {1} has added {2} to their bank account from a secure loot.", DateTime.Now, _cInfo.playerName, _currencyRemoved)); sw.WriteLine(); sw.Flush(); sw.Close(); } } } else { string _message = "Could not find any {Name} in a near by secure loot."; _message = _message.Replace("{Name}", Ingame_Coin); ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _message + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } } else { ChatHook.ChatMessage(_cInfo, ChatHook.Player_Name_Color + _cInfo.playerName + LoadConfig.Chat_Response_Color + " you input an invalid integer. Type " + ChatHook.Command_Private + Command95 + " #.[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } } }
public static void ChestToBankDeposit(ClientInfo _cInfo, string _amount) { try { if (GameManager.Instance.World.Players.dict.ContainsKey(_cInfo.entityId)) { EntityPlayer _player = GameManager.Instance.World.Players.dict[_cInfo.entityId]; if (_player != null) { ItemValue _itemValue = new ItemValue(ItemClass.GetItem(Ingame_Coin).type, 1, 1, false, null, 1); if (_itemValue != null) { int _coinId = _itemValue.GetItemOrBlockId(); if (int.TryParse(_amount, out int _value)) { if (_value > 0) { int _currencyToRemove = _value; int _currencyRemoved = 0; LinkedList <Chunk> _chunkArray = new LinkedList <Chunk>(); DictionaryList <Vector3i, TileEntity> _tiles = new DictionaryList <Vector3i, TileEntity>(); ChunkClusterList _chunklist = GameManager.Instance.World.ChunkClusters; for (int i = 0; i < _chunklist.Count; i++) { ChunkCluster _chunkCluster = _chunklist[i]; _chunkArray = _chunkCluster.GetChunkArray(); foreach (Chunk _chunk in _chunkArray) { _tiles = _chunk.GetTileEntities(); foreach (TileEntity _tile in _tiles.dict.Values) { TileEntityType type = _tile.GetTileEntityType(); if (type.ToString().Equals("SecureLoot")) { TileEntitySecureLootContainer SecureLoot = (TileEntitySecureLootContainer)_tile; if (SecureLoot.IsUserAllowed(_cInfo.playerId) && !SecureLoot.IsUserAccessing()) { Vector3i vec3i = SecureLoot.ToWorldPos(); if ((vec3i.x - _player.position.x) * (vec3i.x - _player.position.x) + (vec3i.z - _player.position.z) * (vec3i.z - _player.position.z) <= 3 * 3) { if (vec3i.y >= (int)_player.position.y - 3 && vec3i.y <= (int)_player.position.y + 3) { ItemStack[] _items = SecureLoot.items; if (_items != null && _items.Length > 0) { for (int j = 0; j < _items.Length; j++) { if (_currencyToRemove > 0) { if (!_items[j].IsEmpty() && _items[j].itemValue.GetItemOrBlockId() == _coinId) { if (_items[j].count <= _currencyToRemove) { int _newCount = _currencyToRemove - _items[j].count; int _newCount2 = _currencyRemoved + _items[j].count; _currencyToRemove = _newCount; _currencyRemoved = _newCount2; _items[j] = ItemStack.Empty.Clone(); } else { int _newCount = _currencyRemoved + _currencyToRemove; int _newStackCount = _items[j].count - _currencyToRemove; _currencyToRemove = 0; _currencyRemoved = _newCount; _items[j] = new ItemStack(_itemValue, _newStackCount); } _tile.SetModified(); } } } } } } } } } } } if (_currencyRemoved > 0) { if (Deposit_Fee_Percent > 0) { float _fee = _currencyRemoved * ((float)Deposit_Fee_Percent / 100); int _adjustedDeposit = _currencyRemoved - (int)_fee; AddCoinsToBank(_cInfo.playerId, _adjustedDeposit); using (StreamWriter sw = new StreamWriter(filepath, true, Encoding.UTF8)) { sw.WriteLine(string.Format("{0}: {1} {2} has added {3} to their bank account from a secure loot.", DateTime.Now, _cInfo.playerId, _cInfo.playerName, _adjustedDeposit)); sw.WriteLine(); sw.Flush(); sw.Close(); } Phrases.Dict.TryGetValue(643, out string _phrase643); _phrase643 = _phrase643.Replace("{Value}", _adjustedDeposit.ToString()); _phrase643 = _phrase643.Replace("{CoinName}", Ingame_Coin); _phrase643 = _phrase643.Replace("{Percent}", Deposit_Fee_Percent.ToString()); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase643 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); } else { AddCoinsToBank(_cInfo.playerId, _currencyRemoved); using (StreamWriter sw = new StreamWriter(filepath, true, Encoding.UTF8)) { sw.WriteLine(string.Format("{0}: {1} {2} has added {3} to their bank account from a secure loot.", DateTime.Now, _cInfo.playerId, _cInfo.playerName, _currencyRemoved)); sw.WriteLine(); sw.Flush(); sw.Close(); } Phrases.Dict.TryGetValue(644, out string _phrase644); _phrase644 = _phrase644.Replace("{Value}", _currencyRemoved.ToString()); _phrase644 = _phrase644.Replace("{CoinName}", Ingame_Coin); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase644 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); } } else { Phrases.Dict.TryGetValue(645, out string _phrase645); _phrase645 = _phrase645.Replace("{CoinName}", Ingame_Coin); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase645 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); } } else { Phrases.Dict.TryGetValue(646, out string _phrase646); _phrase646 = _phrase646.Replace("{CommandPrivate}", ChatHook.Chat_Command_Prefix1); _phrase646 = _phrase646.Replace("{Command95}", Command95); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase646 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); } } else { Phrases.Dict.TryGetValue(646, out string _phrase646); _phrase646 = _phrase646.Replace("{CommandPrivate}", ChatHook.Chat_Command_Prefix1); _phrase646 = _phrase646.Replace("{Command95}", Command95); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase646 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); } } else { Phrases.Dict.TryGetValue(647, out string _phrase647); ChatHook.ChatMessage(_cInfo, Config.Chat_Response_Color + _phrase647 + "[-]", -1, Config.Server_Response_Name, EChatType.Whisper, null); Log.Out(string.Format("[SERVERTOOLS] Bank operation failed. Unable to find item {0}. Check the default game currency from your items.xml", Ingame_Coin)); } } } } catch (Exception e) { Log.Out(string.Format("[SERVERTOOLS] Error in Bank.ChestToBankDeposit: {0}", e.Message)); } }
public static void ChestToBankDeposit(ClientInfo _cInfo, string _amount) { if (GameManager.Instance.World.Players.dict.ContainsKey(_cInfo.entityId)) { EntityPlayer _player = GameManager.Instance.World.Players.dict[_cInfo.entityId]; if (_player != null) { ItemValue _itemValue = new ItemValue(ItemClass.GetItem(Ingame_Coin).type, 1, 1, false, null, 1); if (_itemValue != null) { int _coinId = _itemValue.GetItemOrBlockId(); if (int.TryParse(_amount, out int _value)) { if (_value > 0) { int _currencyToRemove = _value; int _currencyRemoved = 0; LinkedList <Chunk> _chunkArray = new LinkedList <Chunk>(); DictionaryList <Vector3i, TileEntity> _tiles = new DictionaryList <Vector3i, TileEntity>(); ChunkClusterList _chunklist = GameManager.Instance.World.ChunkClusters; for (int i = 0; i < _chunklist.Count; i++) { ChunkCluster _chunk = _chunklist[i]; _chunkArray = _chunk.GetChunkArray(); foreach (Chunk _c in _chunkArray) { _tiles = _c.GetTileEntities(); foreach (TileEntity _tile in _tiles.dict.Values) { TileEntityType type = _tile.GetTileEntityType(); if (type.ToString().Equals("SecureLoot")) { TileEntitySecureLootContainer SecureLoot = (TileEntitySecureLootContainer)_tile; if (SecureLoot.IsUserAllowed(_cInfo.playerId) && !SecureLoot.IsUserAccessing()) { Vector3i vec3i = SecureLoot.ToWorldPos(); if ((vec3i.x - _player.position.x) * (vec3i.x - _player.position.x) + (vec3i.z - _player.position.z) * (vec3i.z - _player.position.z) <= 3 * 3) { if (vec3i.y >= (int)_player.position.y - 3 && vec3i.y <= (int)_player.position.y + 3) { ItemStack[] _items = SecureLoot.items; if (_items != null && _items.Length > 0) { for (int j = 0; j < _items.Length; j++) { if (_currencyToRemove > 0) { if (!_items[j].IsEmpty() && _items[j].itemValue.GetItemOrBlockId() == _coinId) { if (_items[j].count <= _currencyToRemove) { int _newCount = _currencyToRemove - _items[j].count; int _newCount2 = _currencyRemoved + _items[j].count; _currencyToRemove = _newCount; _currencyRemoved = _newCount2; _items[j] = ItemStack.Empty.Clone(); } else { int _newCount = _currencyRemoved + _currencyToRemove; int _newStackCount = _items[j].count - _currencyToRemove; _currencyToRemove = 0; _currencyRemoved = _newCount; _items[j] = new ItemStack(_itemValue, _newStackCount); } _tile.SetModified(); } } } } } } } } } } } if (_currencyRemoved > 0) { if (Deposit_Fee_Percent > 0) { float _fee = _currencyRemoved * ((float)Deposit_Fee_Percent / 100); int _adjustedDeposit = _currencyRemoved - (int)_fee; AddCoinsToBank(_cInfo.playerId, _adjustedDeposit); string _message = "Deposited {Value} {Name} from the secure loot to your bank account. " + "{Percent}" + "% deposit fee was applied."; _message = _message.Replace("{Value}", _adjustedDeposit.ToString()); _message = _message.Replace("{Name}", Ingame_Coin); _message = _message.Replace("{Percent}", Deposit_Fee_Percent.ToString()); ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _message + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); using (StreamWriter sw = new StreamWriter(filepath, true)) { sw.WriteLine(string.Format("{0}: {1} {2} has added {3} to their bank account from a secure loot.", DateTime.Now, _cInfo.playerId, _cInfo.playerName, _adjustedDeposit)); sw.WriteLine(); sw.Flush(); sw.Close(); } } else { AddCoinsToBank(_cInfo.playerId, _currencyRemoved); string _message = "Deposited {Value} {Name} from the secure loot to your bank account."; _message = _message.Replace("{Value}", _currencyRemoved.ToString()); _message = _message.Replace("{Name}", Ingame_Coin); ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _message + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); using (StreamWriter sw = new StreamWriter(filepath, true)) { sw.WriteLine(string.Format("{0}: {1} {2} has added {3} to their bank account from a secure loot.", DateTime.Now, _cInfo.playerId, _cInfo.playerName, _currencyRemoved)); sw.WriteLine(); sw.Flush(); sw.Close(); } } } else { string _message = "Could not find any {CoinName} in a near by secure loot."; _message = _message.Replace("{CoinName}", Ingame_Coin); ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + _message + "[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } } else { ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + "You input an invalid integer. Type " + ChatHook.Command_Private + Command95 + " #[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } } else { ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + "You input an invalid integer. Type " + ChatHook.Command_Private + Command95 + " #[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); } } else { ChatHook.ChatMessage(_cInfo, LoadConfig.Chat_Response_Color + "The bank coin is not setup correctly, contact the server Admin.[-]", -1, LoadConfig.Server_Response_Name, EChatType.Whisper, null); Log.Out(string.Format("[SERVERTOOLS] Bank operation failed. Unable to find item {0}. Check the default game currency from your items.xml", Ingame_Coin)); } } } }