public void ChangeMoney(Player player, long money) { if (!(player.Controller is PlayerTradeController)) return; PlayerTradeController controller = (PlayerTradeController) player.Controller; Storage storage = player.Equals(controller.Player1) ? controller.Storage1 : controller.Storage2; if(money < storage.Money) controller.RemoveMoney(player, storage.Money - money); else if(money > storage.Money) controller.AddMoney(player, money - storage.Money); }
public void RemoveMoney(Player arrivedFrom, long money) { lock (TradeLock) { if (IsTradeFinished()) return; if (arrivedFrom != Player1 && arrivedFrom != Player2) return; Storage storage = arrivedFrom.Equals(Player1) ? Storage1 : Storage2; if (storage.Locked) { SystemMessages.TradeListLocked.Send(arrivedFrom); return; } if (!Communication.Global.StorageService.RemoveMoney(arrivedFrom, storage, money)) return; Communication.Global.StorageService.AddMoneys(arrivedFrom, arrivedFrom.Inventory, money); CheckLock(arrivedFrom.Equals(Player1) ? Storage2 : Storage1); SystemMessages.YouOfferedMoney(storage.Money).Send(arrivedFrom); SystemMessages.OpponentOfferedMoney(arrivedFrom.PlayerData.Name, storage.Money).Send( arrivedFrom.Equals(Player1) ? Player2 : Player1); UpdateWindow(); } }
public void Lock(Player arrivedFrom) { lock (TradeLock) { if (IsTradeFinished()) return; if (arrivedFrom != Player1 && arrivedFrom != Player2) return; if (arrivedFrom.Equals(Player1)) { Storage1.Locked = !Storage1.Locked; if (Storage1.Locked) SystemMessages.OpponentLockedTradeList(Player1.PlayerData.Name).Send(Player1, Player2); } else { Storage2.Locked = !Storage2.Locked; if (Storage2.Locked) SystemMessages.OpponentLockedTradeList(Player2.PlayerData.Name).Send(Player1, Player2); } if (Storage1.Locked && Storage2.Locked) Accept(); else UpdateWindow(); } }
public void RemoveItem(Player arrivedFrom, int slot, int count) { lock (TradeLock) { if (IsTradeFinished()) return; if (arrivedFrom != Player1 && arrivedFrom != Player2) return; Storage storage = arrivedFrom.Equals(Player1) ? Storage1 : Storage2; if (storage.Locked) { SystemMessages.TradeListLocked.Send(arrivedFrom); return; } StorageItem item = Communication.Global.StorageService.GetItemBySlot(storage, slot); if (item == null) return; if (!Communication.Global.StorageService.AddItem(arrivedFrom, arrivedFrom.Inventory, item.ItemId, count)) return; CheckLock(storage.Equals(Storage1) ? Storage2 : Storage1); Communication.Global.StorageService.RemoveItem(arrivedFrom, storage, slot - 20, count); SystemMessages.YouRemovedItemNameXItemAmountToTrade(item.ItemId, item.Amount).Send(arrivedFrom); SystemMessages.OpponentRemovedItemNameItemAmount(arrivedFrom.PlayerData.Name, item.ItemId, count).Send( arrivedFrom.Equals(Player1) ? Player2 : Player1); UpdateWindow(); } }