示例#1
0
        private void Reprocess(Character character, ItemEntity item, Client client)
        {
            if (item.Quantity < item.Type.PortionSize)
            {
                throw new QuantityLessThanMinimumPortion(item.Type);
            }

            int leftovers         = item.Quantity % item.Type.PortionSize;
            int quantityToProcess = item.Quantity - leftovers;

            List <ReprocessingDB.Recoverables> recoverablesList = this.ReprocessingDB.GetRecoverables(item.Type.ID);

            foreach (ReprocessingDB.Recoverables recoverable in recoverablesList)
            {
                int ratio = recoverable.AmountPerBatch * quantityToProcess / item.Type.PortionSize;

                double efficiency = this.CalculateEfficiency(character, recoverable.TypeID);

                int quantityForClient = (int)(efficiency * (1.0 - this.mCorporation.TaxRate) * ratio);

                // create the new item
                ItemEntity newItem = this.ItemFactory.CreateSimpleItem(this.TypeManager[recoverable.TypeID], character, this.mStation,
                                                                       Flags.Hangar, quantityForClient);
                // notify the client about the new item
                client.NotifyMultiEvent(OnItemChange.BuildNewItemChange(newItem));
            }
        }
示例#2
0
文件: ship.cs 项目: lanicon/EVESharp
        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);
        }
示例#3
0
        private void CreateCmd(string[] argv, CallInformation call)
        {
            if (argv.Length < 2)
            {
                throw new SlashError("create takes at least one argument");
            }

            int typeID   = int.Parse(argv[1]);
            int quantity = 1;

            if (argv.Length > 2)
            {
                quantity = int.Parse(argv[2]);
            }

            if (call.Client.StationID == null)
            {
                throw new SlashError("Creating items can only be done at station");
            }
            // ensure the typeID exists
            if (this.TypeManager.ContainsKey(typeID) == false)
            {
                throw new SlashError("The specified typeID doesn't exist");
            }

            // create a new item with the correct locationID
            Station   location  = this.ItemFactory.GetStaticStation((int)call.Client.StationID);
            Character character = this.ItemFactory.GetItem <Character>(call.Client.EnsureCharacterIsSelected());

            Type       itemType = this.TypeManager[typeID];
            ItemEntity item     = this.ItemFactory.CreateSimpleItem(itemType, character, location, Flags.Hangar, quantity);

            item.Persist();

            // send client a notification so they can display the item in the hangar
            call.Client.NotifyMultiEvent(OnItemChange.BuildNewItemChange(item));
        }
示例#4
0
        private void GiveSkillCmd(string[] argv, CallInformation call)
        {
            // TODO: NOT NODE-SAFE, MUST REIMPLEMENT TAKING THAT INTO ACCOUNT!
            if (argv.Length != 4)
            {
                throw new SlashError("GiveSkill must have 4 arguments");
            }

            string target    = argv[1].Trim(new [] { '"', ' ' });
            string skillType = argv[2];
            int    level     = int.Parse(argv[3]);

            if (target != "me")
            {
                throw new SlashError("giveskill only supports me for now");
            }

            Character character = this.ItemFactory.GetItem <Character>(call.Client.EnsureCharacterIsSelected());

            if (skillType == "all")
            {
                // player wants all the skills!
                IEnumerable <KeyValuePair <int, Type> > skillTypes =
                    this.TypeManager.Where(x => x.Value.Group.Category.ID == (int)Categories.Skill && x.Value.Published == true);

                Dictionary <int, Skill> injectedSkills = character.InjectedSkillsByTypeID;

                foreach (KeyValuePair <int, Type> pair in skillTypes)
                {
                    // skill already injected, train it to the desired level
                    if (injectedSkills.ContainsKey(pair.Key) == true)
                    {
                        Skill skill = injectedSkills[pair.Key];

                        skill.Level = level;
                        skill.Persist();
                        call.Client.NotifyMultiEvent(new OnSkillTrained(skill));
                    }
                    else
                    {
                        // skill not injected, create it, inject and done
                        Skill skill = this.ItemFactory.CreateSkill(pair.Value, character, level,
                                                                   SkillHistoryReason.GMGiveSkill);

                        call.Client.NotifyMultiEvent(OnItemChange.BuildNewItemChange(skill));
                        call.Client.NotifyMultiEvent(new OnSkillInjected());
                    }
                }
            }
            else
            {
                int skillTypeID = int.Parse(skillType);
                Dictionary <int, Skill> injectedSkills = character.InjectedSkillsByTypeID;

                if (injectedSkills.ContainsKey(skillTypeID) == true)
                {
                    Skill skill = injectedSkills[skillTypeID];

                    skill.Level = level;
                    skill.Persist();
                    call.Client.NotifyMultiEvent(new OnSkillTrained(skill));
                }
                else
                {
                    // skill not injected, create it, inject and done
                    Skill skill = this.ItemFactory.CreateSkill(this.TypeManager[skillTypeID], character, level,
                                                               SkillHistoryReason.GMGiveSkill);

                    call.Client.NotifyMultiEvent(OnItemChange.BuildNewItemChange(skill));
                    call.Client.NotifyMultiEvent(new OnSkillInjected());
                }
            }
        }
示例#5
0
        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);
        }