Example #1
0
        public string IsValidTarget(NWCreature user, NWItem item, NWObject target, Location targetLocation)
        {
            NWItem targetItem    = target.Object;
            float  maxDurability = _durability.GetMaxDurability(targetItem);
            float  durability    = _durability.GetDurability(targetItem);

            if (target.ObjectType != NWScript.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");

            if (skillType == SkillType.Armorsmith)
            {
                if (_perk.GetPCPerkLevel(user.Object, PerkType.ArmorRepair) < techLevel)
                {
                    return("Your level in the 'Armor Repair' perk is too low to use this repair kit.");
                }
            }
            else if (skillType == SkillType.Weaponsmith)
            {
                if (_perk.GetPCPerkLevel(user.Object, PerkType.WeaponRepair) < techLevel)
                {
                    return("Your level in the 'Weapon Repair' perk is too low to use this repair kit.");
                }
            }
            else if (skillType == SkillType.Engineering)
            {
                if (_perk.GetPCPerkLevel(user.Object, PerkType.ElectronicRepair) < techLevel)
                {
                    return("Your level in the 'Electronic Repair' perk is too low to use this repair kit.");
                }
            }

            return(null);
        }
Example #2
0
        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   = _data.Single <PCBaseStructure>(x => x.ID == new Guid(structureID));
            int             maxShieldHP = _base.CalculateMaxShieldHP(structure);
            PCBase          pcBase      = _data.Get <PCBase>(structure.PCBaseID);
            var             playerIDs   = _data.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   = _base.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!");
                }
            }
            pcBase.ShieldHP -= damage;
            if (pcBase.ShieldHP <= 0)
            {
                pcBase.ShieldHP = 0;
            }
            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);
            }

            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.");
            }

            _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(9999), tower.Object);

            var durability = _durability.GetDurability(weapon) - _random.RandomFloat(0.01f, 0.03f);

            _durability.SetDurability(weapon, durability);

            if (pcBase.ShieldHP <= 0)
            {
                pcBase.ShieldHP = 0;

                structure.Durability -= _random.RandomFloat(0.5f, 2.0f);
                if (structure.Durability < 0.0f)
                {
                    structure.Durability = 0.0f;
                }
                attacker.SendMessage("Structure Durability: " + structure.Durability.ToString("0.00"));

                if (structure.Durability <= 0.0f)
                {
                    structure.Durability = 0.0f;
                    BlowUpBase(pcBase);
                    return(true);
                }
            }

            _data.SubmitDataChange(pcBase, DatabaseActionType.Update);
            _data.SubmitDataChange(structure, DatabaseActionType.Update);
            return(true);
        }