public void DurabilityService_GetDurability_InvalidArguments_ShouldThrowException() { INWScript script = Substitute.For <INWScript>(); IColorTokenService color = Substitute.For <IColorTokenService>(); INWNXProfiler nwnxProfiler = Substitute.For <INWNXProfiler>(); INWNXCreature creature = Substitute.For <INWNXCreature>(); DurabilityService service = new DurabilityService(script, color, nwnxProfiler, creature); Assert.Throws(typeof(ArgumentNullException), () => { service.GetDurability(null); }); }
private void DoPlaceStructure() { var data = BaseService.GetPlayerTempData(GetPC()); string canPlaceStructure = BaseService.CanPlaceStructure(GetPC(), data.StructureItem, data.TargetLocation, data.BaseStructureID); var baseStructure = DataService.BaseStructure.GetByID(data.BaseStructureID); if (!string.IsNullOrWhiteSpace(canPlaceStructure)) { GetPC().SendMessage(canPlaceStructure); return; } var position = _.GetPositionFromLocation(data.TargetLocation); int?interiorStyleID = data.StructureItem.GetLocalInt("STRUCTURE_BUILDING_INTERIOR_ID"); int?exteriorStyleID = data.StructureItem.GetLocalInt("STRUCTURE_BUILDING_EXTERIOR_ID"); interiorStyleID = interiorStyleID <= 0 ? null : interiorStyleID; exteriorStyleID = exteriorStyleID <= 0 ? null : exteriorStyleID; var structure = new PCBaseStructure { BaseStructureID = data.BaseStructureID, Durability = DurabilityService.GetDurability(data.StructureItem), LocationOrientation = _.GetFacingFromLocation(data.TargetLocation), LocationX = position.m_X, LocationY = position.m_Y, LocationZ = position.m_Z, PCBaseID = data.PCBaseID, InteriorStyleID = interiorStyleID, ExteriorStyleID = exteriorStyleID, CustomName = string.Empty, ParentPCBaseStructureID = data.ParentStructureID, StructureBonus = data.StructureItem.StructureBonus, StructureModeID = baseStructure.DefaultStructureModeID }; DataService.SubmitDataChange(structure, DatabaseActionType.Insert); // Placing a control tower. Set base shields to 100% if (baseStructure.BaseStructureTypeID == (int)BaseStructureType.ControlTower) { var pcBase = DataService.PCBase.GetByID(data.PCBaseID); pcBase.ShieldHP = BaseService.CalculateMaxShieldHP(structure); DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); } BaseService.SpawnStructure(data.TargetArea, structure.ID); data.StructureItem.Destroy(); EndConversation(); }
public void DurabilityService_GetDurability_ShouldReturn6Point23() { 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); item.GetLocalFloat(Arg.Any <string>()).Returns(6.23f); float result = service.GetDurability(item); Assert.AreEqual(6.23f, result); }
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); }
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); }
public bool Run(params object[] args) { NWCreature attacker = (_.GetLastDamager(Object.OBJECT_SELF)); NWPlaceable tower = (Object.OBJECT_SELF); NWItem weapon = (_.GetLastWeaponUsed(attacker.Object)); int damage = _.GetTotalDamageDealt(); var structureID = tower.GetLocalString("PC_BASE_STRUCTURE_ID"); PCBaseStructure structure = DataService.Single <PCBaseStructure>(x => x.ID == new Guid(structureID)); int maxShieldHP = BaseService.CalculateMaxShieldHP(structure); PCBase pcBase = DataService.Get <PCBase>(structure.PCBaseID); var playerIDs = DataService.Where <PCBasePermission>(x => x.PCBaseID == structure.PCBaseID && !x.IsPublicPermission) .Select(s => s.PlayerID); var toNotify = NWModule.Get().Players.Where(x => playerIDs.Contains(x.GlobalID)); DateTime timer = DateTime.UtcNow.AddSeconds(30); string clock = timer.ToString(CultureInfo.InvariantCulture); string sector = BaseService.GetSectorOfLocation(attacker.Location); if (DateTime.UtcNow <= DateTime.Parse(clock)) { foreach (NWPlayer player in toNotify) { player.SendMessage("Your base in " + attacker.Area.Name + " " + sector + " is under attack!"); } } // Apply damage to the shields. Never fall below 0. pcBase.ShieldHP -= damage; if (pcBase.ShieldHP <= 0) { pcBase.ShieldHP = 0; } // Calculate the amount of shield percentage remaining. If the tower is in reinforced mode, HP // will always be set back to 25% of shields. float hpPercentage = (float)pcBase.ShieldHP / (float)maxShieldHP * 100.0f; if (hpPercentage <= 25.0f && pcBase.ReinforcedFuel > 0) { pcBase.IsInReinforcedMode = true; pcBase.ShieldHP = (int)(maxShieldHP * 0.25f); hpPercentage = (float)pcBase.ShieldHP / (float)maxShieldHP * 100.0f; } // Notify the attacker. attacker.SendMessage("Tower Shields: " + hpPercentage.ToString("0.00") + "%"); if (pcBase.IsInReinforcedMode) { attacker.SendMessage("Control tower is in reinforced mode and cannot be damaged. Reinforced mode will be disabled when the tower runs out of fuel."); } // HP is tracked in the database. Heal the placeable so it doesn't get destroyed. _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(9999), tower.Object); var durability = DurabilityService.GetDurability(weapon) - RandomService.RandomFloat(0.01f, 0.03f); DurabilityService.SetDurability(weapon, durability); // If the shields have fallen to zero, the tower will begin to take structure damage. if (pcBase.ShieldHP <= 0) { pcBase.ShieldHP = 0; structure.Durability -= RandomService.RandomFloat(0.5f, 2.0f); if (structure.Durability < 0.0f) { structure.Durability = 0.0f; } attacker.SendMessage("Structure Durability: " + structure.Durability.ToString("0.00")); // If the structure durability drops to zero, destroy everything in the base. if (structure.Durability <= 0.0f) { structure.Durability = 0.0f; BaseService.ClearPCBaseByID(pcBase.ID, true, false); return(true); } } DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); DataService.SubmitDataChange(structure, DatabaseActionType.Update); return(true); }