private ItemInstance MakeItemInstance(DbDataReader reader)
        {
            ulong        instanceId   = (ulong)reader.GetInt64("id");
            ItemInstance itemInstance = new ItemInstance(instanceId);

            itemInstance.ownerId = reader.GetInt32("owner_id");

            ItemZoneType zone         = (ItemZoneType)reader.GetByte("zone");
            byte         bag          = reader.GetByte("container");
            short        slot         = reader.GetInt16("slot");
            ItemLocation itemLocation = new ItemLocation(zone, bag, slot);

            itemInstance.location = itemLocation;

            itemInstance.baseId = reader.GetInt32("base_id");

            itemInstance.quantity = reader.GetByte("quantity");

            itemInstance.statuses = (ItemStatuses)reader.GetInt32("statuses");

            itemInstance.currentEquipSlot = (ItemEquipSlots)reader.GetInt32("current_equip_slot");

            itemInstance.currentDurability = reader.GetInt32("current_durability");
            itemInstance.maximumDurability = reader.GetInt32("plus_maximum_durability");
            if (itemInstance.maximumDurability == 0)
            {
                itemInstance.maximumDurability = 10;                                      //toDo  update item library.  items shouldnt have 0 for core stats
            }
            itemInstance.enhancementLevel = reader.GetByte("enhancement_level");

            itemInstance.specialForgeLevel = reader.GetByte("special_forge_level");

            itemInstance.physical = reader.GetInt16("physical");
            itemInstance.magical  = reader.GetInt16("magical");

            itemInstance.hardness         = reader.GetByte("hardness");
            itemInstance.plusPhysical     = reader.GetInt16("plus_physical");
            itemInstance.plusMagical      = reader.GetInt16("plus_magical");
            itemInstance.plusGp           = reader.GetInt16("plus_gp");
            itemInstance.plusWeight       = (short)(reader.GetInt16("plus_weight") * 10); //TODO REMOVE THIS MULTIPLICATION AND FIX TRHOUGHOUT CODE
            itemInstance.plusRangedEff    = reader.GetInt16("plus_ranged_eff");
            itemInstance.plusReservoirEff = reader.GetInt16("plus_reservoir_eff");

            int gemSlotNum   = 0;
            int gemSlot1Type = reader.GetByte("gem_slot_1_type");

            if (gemSlot1Type != 0)
            {
                gemSlotNum++;
            }
            int gemSlot2Type = reader.GetByte("gem_slot_2_type");

            if (gemSlot2Type != 0)
            {
                gemSlotNum++;
            }
            int gemSlot3Type = reader.GetByte("gem_slot_3_type");

            if (gemSlot3Type != 0)
            {
                gemSlotNum++;
            }
            GemSlot[] gemSlot = new GemSlot[gemSlotNum];

            itemInstance.enchantId    = reader.GetInt32("enchant_id");
            itemInstance.gp           = reader.GetInt16("plus_gp");
            itemInstance.type         = (ItemType)Enum.Parse(typeof(ItemType), reader.GetString("item_type"));
            itemInstance.quality      = (ItemQualities)Enum.Parse(typeof(ItemQualities), reader.GetString("quality"), true);
            itemInstance.maxStackSize = reader.GetByte("max_stack_size");

            if (reader.GetBoolean("es_hand_r"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.RightHand;
            }
            if (reader.GetBoolean("es_hand_l"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.LeftHand;
            }
            if (reader.GetBoolean("es_quiver"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Quiver;
            }
            if (reader.GetBoolean("es_head"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Head;
            }
            if (reader.GetBoolean("es_body"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Torso;
            }
            if (reader.GetBoolean("es_legs"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Legs;
            }
            if (reader.GetBoolean("es_arms"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Arms;
            }
            if (reader.GetBoolean("es_feet"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Feet;
            }
            if (reader.GetBoolean("es_mantle"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Cloak;
            }
            if (reader.GetBoolean("es_ring"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Ring;
            }
            if (reader.GetBoolean("es_earring"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Earring;
            }
            if (reader.GetBoolean("es_necklace"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Necklace;
            }
            if (reader.GetBoolean("es_belt"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Belt;
            }
            if (reader.GetBoolean("es_talkring"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.Talkring;
            }
            if (reader.GetBoolean("es_avatar_head"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.AvatarHead;
            }
            if (reader.GetBoolean("es_avatar_body"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.AvatarTorso;
            }
            if (reader.GetBoolean("es_avatar_legs"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.AvatarLegs;
            }
            if (reader.GetBoolean("es_avatar_arms"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.AvatarArms;
            }
            if (reader.GetBoolean("es_avatar_feet"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.AvatarFeet;
            }
            if (reader.GetBoolean("es_avatar_feet"))
            {
                itemInstance.equipAllowedSlots |= ItemEquipSlots.AvatarCloak;
            }

            if (reader.GetBoolean("req_hum_m"))
            {
                itemInstance.requiredRaces |= Races.HumanMale;
            }
            if (reader.GetBoolean("req_hum_f"))
            {
                itemInstance.requiredRaces |= Races.HumanFemale;
            }
            if (reader.GetBoolean("req_elf_m"))
            {
                itemInstance.requiredRaces |= Races.ElfMale;
            }
            if (reader.GetBoolean("req_elf_f"))
            {
                itemInstance.requiredRaces |= Races.ElfFemale;
            }
            if (reader.GetBoolean("req_dwf_m"))
            {
                itemInstance.requiredRaces |= Races.DwarfMale;
            }
            if (reader.GetBoolean("req_por_m"))
            {
                itemInstance.requiredRaces |= Races.PorkulMale;
            }
            if (reader.GetBoolean("req_por_f"))
            {
                itemInstance.requiredRaces |= Races.PorkulFemale;
            }
            if (reader.GetBoolean("req_gnm_f"))
            {
                itemInstance.requiredRaces |= Races.GnomeFemale;
            }

            if (reader.GetBoolean("req_fighter"))
            {
                itemInstance.requiredClasses |= Classes.Fighter;
            }
            if (reader.GetBoolean("req_thief"))
            {
                itemInstance.requiredClasses |= Classes.Thief;
            }
            if (reader.GetBoolean("req_mage"))
            {
                itemInstance.requiredClasses |= Classes.Mage;
            }
            if (reader.GetBoolean("req_priest"))
            {
                itemInstance.requiredClasses |= Classes.Priest;
            }
            if (reader.GetBoolean("req_samurai"))
            {
                itemInstance.requiredClasses |= Classes.Samurai;
            }
            if (reader.GetBoolean("req_bishop"))
            {
                itemInstance.requiredClasses |= Classes.Bishop;
            }
            if (reader.GetBoolean("req_ninja"))
            {
                itemInstance.requiredClasses |= Classes.Ninja;
            }
            if (reader.GetBoolean("req_lord"))
            {
                itemInstance.requiredClasses |= Classes.Lord;
            }
            if (reader.GetBoolean("req_clown"))
            {
                itemInstance.requiredClasses |= Classes.Clown;
            }
            if (reader.GetBoolean("req_alchemist"))
            {
                itemInstance.requiredClasses |= Classes.Alchemist;
            }

            if (reader.GetBoolean("req_lawful"))
            {
                itemInstance.requiredAlignments |= Alignments.Lawful;
            }
            if (reader.GetBoolean("req_neutral"))
            {
                itemInstance.requiredAlignments |= Alignments.Neutral;
            }
            if (reader.GetBoolean("req_chaotic"))
            {
                itemInstance.requiredAlignments |= Alignments.Chaotic;
            }

            itemInstance.requiredStrength     = reader.GetByte("req_str");
            itemInstance.requiredVitality     = reader.GetByte("req_vit");
            itemInstance.requiredDexterity    = reader.GetByte("req_dex");
            itemInstance.requiredAgility      = reader.GetByte("req_agi");
            itemInstance.requiredIntelligence = reader.GetByte("req_int");
            itemInstance.requiredPiety        = reader.GetByte("req_pie");
            itemInstance.requiredLuck         = reader.GetByte("req_luk");

            itemInstance.requiredSoulRank = reader.GetByte("req_soul_rank");
            //todo max soul rank
            itemInstance.requiredLevel = reader.GetByte("req_lvl");

            itemInstance.physicalSlash  = reader.GetByte("phys_slash");
            itemInstance.physicalStrike = reader.GetByte("phys_strike");
            itemInstance.physicalPierce = reader.GetByte("phys_pierce");

            itemInstance.physicalDefenseFire  = reader.GetByte("pdef_fire");
            itemInstance.physicalDefenseWater = reader.GetByte("pdef_water");
            itemInstance.physicalDefenseWind  = reader.GetByte("pdef_wind");
            itemInstance.physicalDefenseEarth = reader.GetByte("pdef_earth");
            itemInstance.physicalDefenseLight = reader.GetByte("pdef_light");
            itemInstance.physicalDefenseDark  = reader.GetByte("pdef_dark");

            itemInstance.magicalAttackFire  = reader.GetByte("matk_fire");
            itemInstance.magicalAttackWater = reader.GetByte("matk_water");
            itemInstance.magicalAttackWind  = reader.GetByte("matk_wind");
            itemInstance.magicalAttackEarth = reader.GetByte("matk_earth");
            itemInstance.magicalAttackLight = reader.GetByte("matk_light");
            itemInstance.magicalAttackDark  = reader.GetByte("matk_dark");

            itemInstance.hp   = reader.GetByte("seffect_hp");
            itemInstance.mp   = reader.GetByte("seffect_mp");
            itemInstance.str  = reader.GetByte("seffect_str");
            itemInstance.vit  = reader.GetByte("seffect_vit");
            itemInstance.dex  = reader.GetByte("seffect_dex");
            itemInstance.agi  = reader.GetByte("seffect_agi");
            itemInstance.@int = reader.GetByte("seffect_int");
            itemInstance.pie  = reader.GetByte("seffect_pie");
            itemInstance.luk  = reader.GetByte("seffect_luk");

            itemInstance.resistPoison    = reader.GetByte("res_poison");
            itemInstance.resistParalyze  = reader.GetByte("res_paralyze");
            itemInstance.resistPetrified = reader.GetByte("res_petrified");
            itemInstance.resistFaint     = reader.GetByte("res_faint");
            itemInstance.resistBlind     = reader.GetByte("res_blind");
            itemInstance.resistSleep     = reader.GetByte("res_sleep");
            itemInstance.resistSilence   = reader.GetByte("res_silent");
            itemInstance.resistCharm     = reader.GetByte("res_charm");
            itemInstance.resistConfusion = reader.GetByte("res_confusion");
            itemInstance.resistFear      = reader.GetByte("res_fear");

            //itemInstance.StatusMalus = (ItemStatusEffect)Enum.Parse(typeof(ItemStatusEffect), reader.GetString("status_malus"));
            itemInstance.statusMalusPercent = reader.GetInt32("status_percent");

            itemInstance.objectType = reader.GetString("object_type");              //not sure what this is for
            itemInstance.equipSlot2 = reader.GetString("equip_slot");               //not sure what this is for

            itemInstance.isUseableInTown    = !reader.GetBoolean("no_use_in_town"); //not sure what this is for
            itemInstance.isStorable         = !reader.GetBoolean("no_storage");
            itemInstance.isDiscardable      = !reader.GetBoolean("no_discard");
            itemInstance.isSellable         = !reader.GetBoolean("no_sell");
            itemInstance.isTradeable        = !reader.GetBoolean("no_trade");
            itemInstance.isTradableAfterUse = !reader.GetBoolean("no_trade_after_used");
            itemInstance.isStealable        = !reader.GetBoolean("no_stolen");

            itemInstance.isGoldBorder = reader.GetBoolean("gold_border");

            //itemInstance.Lore = reader.GetString("lore");

            itemInstance.iconId = reader.GetInt32("icon");

            itemInstance.talkRingName = "";
            //TODO fix all the data types once mysql is implemented
            itemInstance.bagSize = reader.GetByte("num_of_bag_slots");

            //grade,
            //weight
            itemInstance.weight = (int)(reader.GetDouble("weight") * 10000); // TODO DOUBLE CHECK THIS IS CORRECT SCALE

            //auction
            itemInstance.consignerSoulName      = reader.IsDBNull("consigner_soul_name") ? "" : reader.GetString("consigner_soul_name");
            itemInstance.secondsUntilExpiryTime = reader.IsDBNull("expiry_datetime") ? 0 : CalcSecondsToExpiry(reader.GetInt64("expiry_datetime"));
            itemInstance.minimumBid             = reader.IsDBNull("min_bid") ? 0 : (ulong)reader.GetInt64("min_bid");
            itemInstance.buyoutPrice            = reader.IsDBNull("buyout_price") ? 0 : (ulong)reader.GetInt64("buyout_price");
            itemInstance.comment = reader.IsDBNull("comment") ? "" : reader.GetString("comment");

            //enhancement
            itemInstance = CalcEnhancement(itemInstance);

            return(itemInstance);
        }
示例#2
0
 public void UpdateEnhancementLevel(ItemInstance itemInstance)
 {
     _itemDao.UpdateItemEnhancementLevel(itemInstance.instanceId, itemInstance.enhancementLevel);
 }
示例#3
0
        //auction functions
        public MoveResult Exhibit(ItemLocation itemLocation, byte exhibitSlot, byte quantity, int auctionTimeSelector, ulong minBid, ulong buyoutPrice, string comment)
        {
            const int    MAX_LOTS        = 10; //TODO update with dimento?
            ItemInstance fromItem        = _character.itemLocationVerifier.GetItem(itemLocation);
            ItemLocation exhibitLocation = new ItemLocation(ItemZoneType.ProbablyAuctionLots, 0, exhibitSlot);
            bool         hasToItem       = _character.itemLocationVerifier.HasItem(exhibitLocation);
            MoveResult   moveResult      = new MoveResult();

            //check possible errors. these should only occur if client is compromised
            if (hasToItem)
            {
                throw new AuctionException(AuctionExceptionType.InvalidListing);
            }
            //if (currentNumLots >= MAX_LOTS) throw new AuctionException(AuctionExceptionType.LotSlotsFull); //TODO check later if too many slots
            if (_character.equippedItems.ContainsValue(fromItem))
            {
                throw new AuctionException(AuctionExceptionType.EquipListing);                                                   //TODO Might not work because equipment hasn't been fleshed out
            }
            //if (false) throw new AuctionException(AuctionExceptionType.InvalidListing); //TODO CHECK IF INVALID ITEM like protect or no trade
            //if (false) throw new AuctionException(AuctionExceptionType.LotDimentoMedalExpired); //TODO CHECK DIMETO MEDAL ROYAL ACCOUNT STATUS
            //if (false) throw new AuctionException(AuctionExceptionType.ItemAlreadyListed); //TODO CHECK ITEM ALREADY_LISTED items must have a unique instance ID!
            if (fromItem is null || quantity == 0)
            {
                throw new AuctionException(AuctionExceptionType.Generic);
            }
            if (quantity > fromItem.quantity)
            {
                throw new AuctionException(AuctionExceptionType.IllegalItemAmount);
            }

            //int gold = _auctionDao.SelectGold(_client.Character); //TODO CHECK GOLD AMOUNT AND SUBTRACT, WAIT FOR UTIL FUNCTION
            //InventoryService iManager = new InventoryService(_client); //remove this
            //iManager.SubtractGold((int) Math.Ceiling(auctionItem.BuyoutPrice * LISTING_FEE_PERCENT));

            if (quantity == fromItem.quantity)
            {
                moveResult = MoveItemPlace(exhibitLocation, fromItem);
            }
            else if (quantity < fromItem.quantity)
            {
                moveResult = MoveItemPlaceQuantity(exhibitLocation, fromItem, quantity);
            }

            moveResult.destItem.consignerSoulName = _character.name;
            moveResult.destItem.minimumBid        = minBid;
            moveResult.destItem.buyoutPrice       = buyoutPrice;
            moveResult.destItem.comment           = comment;

            int       auctionTimeInSecondsFromNow = 0;
            const int SECONDS_PER_FOUR_HOURS      = 60 * 60 * 4;

            switch (auctionTimeSelector) //TODO something not working
            {
            case 0:                      // 4 hours
                auctionTimeInSecondsFromNow = SECONDS_PER_FOUR_HOURS;
                break;

            case 1:     // 8 hours
                auctionTimeInSecondsFromNow = SECONDS_PER_FOUR_HOURS * 2;
                break;

            case 2:     // 12 hours
                auctionTimeInSecondsFromNow = SECONDS_PER_FOUR_HOURS * 3;
                break;

            case 3:     // 24 hours
                auctionTimeInSecondsFromNow = SECONDS_PER_FOUR_HOURS * 6;
                break;
            }

            moveResult.destItem.secondsUntilExpiryTime = auctionTimeInSecondsFromNow;

            _itemDao.UpdateAuctionExhibit(moveResult.destItem);
            return(moveResult);
        }
示例#4
0
        /// <summary>
        ///     Used when the there is an item already in the end location,the quantity moved is equal to the total quantity<br />
        ///     of items in the original location, and the item at the end location is a different base item or stacked full.
        /// </summary>
        /// <param name="from">Swap back to this location.</param>
        /// <param name="to">Move to this location.</param>
        /// <param name="fromItem">Move this item.</param>
        /// <param name="toItem">Swap this item.</param>
        /// <returns>Result with the origin item and destination item being the swapped items.</returns>
        private MoveResult MoveItemSwap(ItemLocation from, ItemLocation to, ItemInstance fromItem, ItemInstance toItem)
        {
            MoveResult moveResult = new MoveResult(MoveType.Swap);

            _character.itemLocationVerifier.PutItem(to, fromItem);
            _character.itemLocationVerifier.PutItem(from, toItem);
            moveResult.destItem   = fromItem;
            moveResult.originItem = toItem;

            ulong[]        instanceIds = new ulong[2];
            ItemLocation[] locs        = new ItemLocation[2];
            instanceIds[0] = moveResult.originItem.instanceId;
            locs[0]        = moveResult.originItem.location;
            instanceIds[1] = moveResult.destItem.instanceId;
            locs[1]        = moveResult.destItem.location;

            _itemDao.UpdateItemLocations(instanceIds, locs);

            return(moveResult);
        }