コード例 #1
0
        public void DurabilityService_GetMaxDurability_InvalidArguments_ShouldThrowException()
        {
            INWScript          script  = Substitute.For <INWScript>();
            IColorTokenService color   = Substitute.For <IColorTokenService>();
            DurabilityService  service = new DurabilityService(script, color);

            Assert.Throws(typeof(ArgumentNullException), () =>
            {
                service.GetMaxDurability(null);
            });
        }
コード例 #2
0
        public string CanApply(NWPlayer player, NWItem target, params string[] args)
        {
            var maxDurability = DurabilityService.GetMaxDurability(target);

            if (maxDurability >= 100)
            {
                return("You cannot improve that item's maximum durability any further.");
            }

            return(null);
        }
コード例 #3
0
        public void DurabilityService_GetMaxDurability_ShouldReturnDefault()
        {
            INWScript          script  = Substitute.For <INWScript>();
            IColorTokenService color   = Substitute.For <IColorTokenService>();
            DurabilityService  service = new DurabilityService(script, color);
            NWItem             item    = Substitute.For <NWItem>(script, service);

            item.BaseItemType.Returns(x => BASE_ITEM_LONGSWORD);

            float result = service.GetMaxDurability(item);

            Assert.AreEqual(30.0f, result);
        }
コード例 #4
0
        public void DurabilityService_GetMaxDurability_InvalidType_ShouldReturnNegative1()
        {
            INWScript          script  = Substitute.For <INWScript>();
            IColorTokenService color   = Substitute.For <IColorTokenService>();
            DurabilityService  service = new DurabilityService(script, color);
            NWItem             item    = Substitute.For <NWItem>(script, service);

            item.BaseItemType.Returns(x => BASE_ITEM_BLANK_SCROLL);

            float result = service.GetMaxDurability(item);

            Assert.AreEqual(-1.0f, result);
        }
コード例 #5
0
        public void DurabilityService_GetMaxDurability_ShouldReturn4()
        {
            INWScript          script  = Substitute.For <INWScript>();
            IColorTokenService color   = Substitute.For <IColorTokenService>();
            DurabilityService  service = new DurabilityService(script, color);
            NWItem             item    = Substitute.For <NWItem>(script, service);

            item.BaseItemType.Returns(x => NWScript.BASE_ITEM_LONGSWORD);
            item.GetLocalInt(Arg.Any <string>()).Returns(4);

            float result = service.GetMaxDurability(item);

            Assert.AreEqual(4, result);
        }
コード例 #6
0
        public void Apply(NWPlayer player, NWItem target, params string[] args)
        {
            var maxDurability = DurabilityService.GetMaxDurability(target);
            var curDurability = DurabilityService.GetDurability(target);

            int   value    = Convert.ToInt32(args[0]);
            float newValue = maxDurability + value;

            if (newValue > 100)
            {
                newValue = 100;
            }
            maxDurability  = newValue;
            curDurability += value;

            DurabilityService.SetMaxDurability(target, maxDurability);
            DurabilityService.SetDurability(target, curDurability);
        }
コード例 #7
0
ファイル: RepairKit.cs プロジェクト: NZNightwolf/SWLOR_NWN
        public string IsValidTarget(NWCreature user, NWItem item, NWObject target, Location targetLocation)
        {
            NWItem targetItem    = target.Object;
            float  maxDurability = DurabilityService.GetMaxDurability(targetItem);
            float  durability    = DurabilityService.GetDurability(targetItem);

            if (target.ObjectType != OBJECT_TYPE_ITEM)
            {
                return("Only items may be targeted by repair kits.");
            }

            if (targetItem.CustomItemType != (CustomItemType)item.GetLocalInt("REPAIR_CUSTOM_ITEM_TYPE_ID"))
            {
                return("You cannot repair that item with this repair kit.");
            }

            if (maxDurability <= 0.0f ||
                durability >= maxDurability)
            {
                return("That item does not need to be repaired.");
            }

            if (durability <= 0.0f)
            {
                return("That item is broken and cannot be repaired.");
            }

            if (maxDurability <= 0.1f)
            {
                return("You cannot repair that item any more.");
            }

            SkillType skillType = GetSkillType(item);
            int       techLevel = item.GetLocalInt("TECH_LEVEL");

            return(null);
        }
コード例 #8
0
ファイル: CraftCreateItem.cs プロジェクト: Miskol23/SWLOR_NWN
        private void RunCreateItem(NWPlayer player)
        {
            foreach (var effect in player.Effects)
            {
                if (_.GetEffectTag(effect) == "CRAFTING_IMMOBILIZATION")
                {
                    _.RemoveEffect(player, effect);
                }
            }

            var model = CraftService.GetPlayerCraftingData(player);

            CraftBlueprint blueprint     = DataService.CraftBlueprint.GetByID(model.BlueprintID);
            BaseStructure  baseStructure = blueprint.BaseStructureID == null ? null : DataService.BaseStructure.GetByID(Convert.ToInt32(blueprint.BaseStructureID));
            PCSkill        pcSkill       = SkillService.GetPCSkill(player, blueprint.SkillID);

            int   pcEffectiveLevel = CraftService.CalculatePCEffectiveLevel(player, pcSkill.Rank, (SkillType)blueprint.SkillID);
            int   itemLevel        = model.AdjustedLevel;
            int   atmosphereBonus  = CraftService.CalculateAreaAtmosphereBonus(player.Area);
            float chance           = CalculateBaseChanceToAddProperty(pcEffectiveLevel, itemLevel, atmosphereBonus);
            float equipmentBonus   = CalculateEquipmentBonus(player, (SkillType)blueprint.SkillID);

            if (chance <= 1.0f)
            {
                player.FloatingText(ColorTokenService.Red("Critical failure! You don't have enough skill to create that item. All components were lost."));
                CraftService.ClearPlayerCraftingData(player, true);
                return;
            }

            int    luckyBonus   = PerkService.GetCreaturePerkLevel(player, PerkType.Lucky);
            var    craftedItems = new List <NWItem>();
            NWItem craftedItem  = (_.CreateItemOnObject(blueprint.ItemResref, player.Object, blueprint.Quantity));

            craftedItem.IsIdentified = true;
            craftedItems.Add(craftedItem);

            // If item isn't stackable, loop through and create as many as necessary.
            if (craftedItem.StackSize < blueprint.Quantity)
            {
                for (int x = 2; x <= blueprint.Quantity; x++)
                {
                    craftedItem = (_.CreateItemOnObject(blueprint.ItemResref, player.Object));
                    craftedItem.IsIdentified = true;
                    craftedItems.Add(craftedItem);
                }
            }

            // Recommended level gets set regardless if all item properties make it on the final product.
            // Also mark who crafted the item. This is later used for display on the item's examination event.
            foreach (var item in craftedItems)
            {
                item.RecommendedLevel = itemLevel < 0 ? 0 : itemLevel;
                item.SetLocalString("CRAFTER_PLAYER_ID", player.GlobalID.ToString());

                BaseService.ApplyCraftedItemLocalVariables(item, baseStructure);
            }

            if (RandomService.Random(1, 100) <= luckyBonus)
            {
                chance += RandomService.Random(1, luckyBonus);
            }

            int successAmount = 0;

            foreach (var component in model.MainComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.SecondaryComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.TertiaryComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }
            foreach (var component in model.EnhancementComponents)
            {
                var result = RunComponentBonusAttempt(player, component, equipmentBonus, chance, craftedItems);
                successAmount += result.Item1;
                chance         = result.Item2;
            }

            // Structures gain increased durability based on the blueprint
            if (baseStructure != null)
            {
                foreach (var item in craftedItems)
                {
                    var maxDur = DurabilityService.GetMaxDurability(item);
                    maxDur += (float)baseStructure.Durability;
                    DurabilityService.SetMaxDurability(item, maxDur);
                    DurabilityService.SetDurability(item, maxDur);
                }
            }

            player.SendMessage("You created " + blueprint.Quantity + "x " + blueprint.ItemName + "!");
            int   baseXP = 750 + successAmount * RandomService.Random(1, 50);
            float xp     = SkillService.CalculateRegisteredSkillLevelAdjustedXP(baseXP, model.AdjustedLevel, pcSkill.Rank);

            bool exists = DataService.PCCraftedBlueprint.ExistsByPlayerIDAndCraftedBlueprintID(player.GlobalID, blueprint.ID);

            if (!exists)
            {
                xp = xp * 1.50f;
                player.SendMessage("You receive an XP bonus for crafting this item for the first time.");

                var pcCraftedBlueprint = new PCCraftedBlueprint
                {
                    CraftBlueprintID = blueprint.ID,
                    DateFirstCrafted = DateTime.UtcNow,
                    PlayerID         = player.GlobalID
                };

                DataService.SubmitDataChange(pcCraftedBlueprint, DatabaseActionType.Insert);
            }

            SkillService.GiveSkillXP(player, blueprint.SkillID, (int)xp);
            CraftService.ClearPlayerCraftingData(player, true);
            player.SetLocalInt("LAST_CRAFTED_BLUEPRINT_ID_" + blueprint.CraftDeviceID, blueprint.ID);
        }