public PyDataType AssembleShip(PyInteger itemID, CallInformation call) { int callerCharacterID = call.Client.EnsureCharacterIsSelected(); int stationID = call.Client.EnsureCharacterIsInStation(); // ensure the item is loaded somewhere in this node // this will usually be taken care by the EVE Client if (this.ItemFactory.TryGetItem(itemID, out Ship ship) == false) { throw new CustomError("Ships not loaded for player and hangar!"); } Character character = this.ItemFactory.GetItem <Character>(callerCharacterID); if (ship.OwnerID != callerCharacterID) { throw new AssembleOwnShipsOnly(ship.OwnerID); } // do not do anything if item is already assembled if (ship.Singleton == true) { return(new ShipAlreadyAssembled(ship.Type)); } // first split the stack if (ship.Quantity > 1) { // subtract one off the stack ship.Quantity -= 1; ship.Persist(); // notify the quantity change call.Client.NotifyMultiEvent(OnItemChange.BuildQuantityChange(ship, ship.Quantity + 1)); // create the new item in the database Station station = this.ItemFactory.GetStaticStation(stationID); ship = this.ItemFactory.CreateShip(ship.Type, station, character); // notify the new item call.Client.NotifyMultiEvent(OnItemChange.BuildNewItemChange(ship)); } else { // stack of one, simple as changing the singleton flag ship.Singleton = true; call.Client.NotifyMultiEvent(OnItemChange.BuildSingletonChange(ship, false)); } // save the ship ship.Persist(); return(null); }
public PyDataType AssembleCargoContainer(PyInteger containerID, PyDataType ignored, PyDecimal ignored2, CallInformation call) { ItemEntity item = this.ItemFactory.GetItem(containerID); if (item.OwnerID != call.Client.EnsureCharacterIsSelected()) { throw new TheItemIsNotYoursToTake(containerID); } // ensure the item is a cargo container switch (item.Type.Group.ID) { case (int)Groups.CargoContainer: case (int)Groups.SecureCargoContainer: case (int)Groups.AuditLogSecureContainer: case (int)Groups.FreightContainer: case (int)Groups.Tool: case (int)Groups.MobileWarpDisruptor: break; default: throw new ItemNotContainer(containerID); } bool oldSingleton = item.Singleton; // update singleton item.Singleton = true; item.Persist(); // notify the client call.Client.NotifyMultiEvent(OnItemChange.BuildSingletonChange(item, oldSingleton)); return(null); }
public PyDataType InjectSkillIntoBrain(PyList itemIDs, CallInformation call) { foreach (PyInteger item in itemIDs.GetEnumerable <PyInteger>()) { try { // get the item by it's ID and change the location of it Skill skill = this.ItemFactory.GetItem <Skill>(item); // check if the character already has this skill injected if (this.Character.InjectedSkillsByTypeID.ContainsKey(skill.Type.ID) == true) { throw new CharacterAlreadyKnowsSkill(skill.Type); } // is this a stack of skills? if (skill.Quantity > 1) { // add one of the skill into the character's brain Skill newStack = this.ItemFactory.CreateSkill(skill.Type, this.Character, 0, SkillHistoryReason.None); // subtract one from the quantity skill.Quantity -= 1; // save to database skill.Persist(); // finally notify the client call.Client.NotifyMultiEvent(OnItemChange.BuildQuantityChange(skill, skill.Quantity + 1)); call.Client.NotifyMultiEvent(OnItemChange.BuildNewItemChange(newStack)); } else { // store old values for the notification int oldLocationID = skill.LocationID; Flags oldFlag = skill.Flag; // now set the new values skill.LocationID = this.Character.ID; skill.Flag = Flags.Skill; skill.Level = 0; skill.Singleton = true; // ensure the character has the skill in his/her brain this.Character.AddItem(skill); // ensure the changes are saved skill.Persist(); // notify the character of the change in the item call.Client.NotifyMultiEvent(OnItemChange.BuildLocationChange(skill, oldFlag, oldLocationID)); call.Client.NotifyMultiEvent(OnItemChange.BuildSingletonChange(skill, false)); } } catch (CharacterAlreadyKnowsSkill) { throw; } catch (Exception) { Log.Error($"Cannot inject itemID {item} into {this.Character.ID}'s brain..."); throw; } } // send the skill injected notification to refresh windows if needed call.Client.NotifyMultiEvent(new OnSkillInjected()); return(null); }
public PyDataType UnasembleItems(PyDictionary validIDsByStationID, PyList skipChecks, CallInformation call) { int characterID = call.Client.EnsureCharacterIsSelected(); List <RepairDB.ItemRepackageEntry> entries = new List <RepairDB.ItemRepackageEntry>(); bool ignoreContractVoiding = false; bool ignoreRepackageWithUpgrades = false; foreach (PyString check in skipChecks.GetEnumerable <PyString>()) { if (check == "RepairUnassembleVoidsContract") { ignoreContractVoiding = true; } if (check == "ConfirmRepackageSomethingWithUpgrades") { ignoreRepackageWithUpgrades = true; } } foreach ((PyInteger stationID, PyList itemIDs) in validIDsByStationID.GetEnumerable <PyInteger, PyList>()) { foreach (PyInteger itemID in itemIDs.GetEnumerable <PyInteger>()) { RepairDB.ItemRepackageEntry entry = this.RepairDB.GetItemToRepackage(itemID, characterID, stationID); if (entry.HasContract == true && ignoreContractVoiding == false) { throw new RepairUnassembleVoidsContract(itemID); } if (entry.HasUpgrades == true && ignoreRepackageWithUpgrades == false) { throw new ConfirmRepackageSomethingWithUpgrades(); } if (entry.Damage != 0.0) { throw new CantRepackageDamagedItem(); } entries.Add(entry); } } foreach (RepairDB.ItemRepackageEntry entry in entries) { if (entry.Singleton == false) { continue; } // extra situation, the repair is happening on a item in our node, the client must know immediately if (entry.NodeID == this.Container.NodeID || this.SystemManager.StationBelongsToUs(entry.LocationID) == true) { ItemEntity item = this.ItemFactory.LoadItem(entry.ItemID, out bool loadRequired); // the item is an inventory, take everything out! if (item is ItemInventory inventory) { foreach ((int _, ItemEntity itemInInventory) in inventory.Items) { // if the item is in a rig slot, destroy it if (itemInInventory.IsInRigSlot() == true) { Flags oldFlag = itemInInventory.Flag; this.ItemFactory.DestroyItem(itemInInventory); // notify the client about the change call.Client.NotifyMultiEvent(OnItemChange.BuildLocationChange(itemInInventory, oldFlag, entry.ItemID)); } else { Flags oldFlag = itemInInventory.Flag; // update item's location itemInInventory.LocationID = entry.LocationID; itemInInventory.Flag = Flags.Hangar; // notify the client about the change call.Client.NotifyMultiEvent(OnItemChange.BuildLocationChange(itemInInventory, oldFlag, entry.ItemID)); // save the item itemInInventory.Persist(); } } } // update the singleton flag too item.Singleton = false; call.Client.NotifyMultiEvent(OnItemChange.BuildSingletonChange(item, true)); // load was required, the item is not needed anymore if (loadRequired == true) { this.ItemFactory.UnloadItem(item); } } else { long nodeID = this.SystemManager.GetNodeStationBelongsTo(entry.LocationID); if (nodeID > 0) { Notifications.Nodes.Inventory.OnItemChange change = new Notifications.Nodes.Inventory.OnItemChange(); change.AddChange(entry.ItemID, "singleton", true, false); this.NotificationManager.NotifyNode(nodeID, change); } } // finally repackage the item this.RepairDB.RepackageItem(entry.ItemID, entry.LocationID); // remove any insurance contract for the ship this.InsuranceDB.UnInsureShip(entry.ItemID); } return(null); }