Пример #1
0
        public void Main()
        {
            NWPlaceable     tower       = _.OBJECT_SELF;
            Guid            structureID = new Guid(tower.GetLocalString("PC_BASE_STRUCTURE_ID"));
            PCBaseStructure structure   = DataService.PCBaseStructure.GetByID(structureID);
            int             maxShieldHP = BaseService.CalculateMaxShieldHP(structure);
            var             pcBase      = DataService.PCBase.GetByID(structure.PCBaseID);

            // Regular fuel usage
            if (DateTime.UtcNow >= pcBase.DateFuelEnds && pcBase.Fuel > 0)
            {
                pcBase.Fuel--;
                BaseStructure towerStructure = DataService.BaseStructure.GetByID(structure.BaseStructureID);
                int           fuelRating     = towerStructure.FuelRating;
                int           minutes;

                switch (fuelRating)
                {
                case 1:     // Small
                    minutes = 45;
                    break;

                case 2:     // Medium
                    minutes = 15;
                    break;

                case 3:     // Large
                    minutes = 5;
                    break;

                default:
                    throw new Exception("Invalid fuel rating value: " + fuelRating);
                }

                pcBase.DateFuelEnds = DateTime.UtcNow.AddMinutes(minutes);

                // If a player is manipulating fuel, look for a fuel item and reduce its stack size or destroy it
                NWPlaceable bay = tower.GetLocalObject("CONTROL_TOWER_FUEL_BAY");
                if (bay.IsValid)
                {
                    bool isStronidium = bay.GetLocalBool("CONTROL_TOWER_FUEL_TYPE") == true;
                    if (!isStronidium)
                    {
                        NWItem fuel = _.GetFirstItemInInventory(bay.Object);

                        if (fuel.IsValid)
                        {
                            fuel.ReduceItemStack();
                        }
                    }
                }
            }

            // If completely out of power, show tower in red.
            if (pcBase.Fuel <= 0 && DateTime.UtcNow > pcBase.DateFuelEnds)
            {
                bool outOfPowerHasBeenApplied = false;
                foreach (var effect in tower.Effects)
                {
                    if (_.GetEffectTag(effect) == "CONTROL_TOWER_OUT_OF_POWER")
                    {
                        outOfPowerHasBeenApplied = true;
                        break;
                    }
                }

                if (!outOfPowerHasBeenApplied)
                {
                    Effect outOfPowerEffect = _.EffectVisualEffect(VisualEffect.Vfx_Dur_Aura_Red);
                    outOfPowerEffect = _.TagEffect(outOfPowerEffect, "CONTROL_TOWER_OUT_OF_POWER");
                    _.ApplyEffectToObject(DurationType.Permanent, outOfPowerEffect, tower.Object);

                    var instances = NWModule.Get().Areas.Where(x => x.GetLocalString("PC_BASE_STRUCTURE_ID") == structureID.ToString());

                    foreach (var instance in instances)
                    {
                        BaseService.ToggleInstanceObjectPower(instance, false);
                    }
                }
            }
            else
            {
                bool outOfPowerWasRemoved = false;
                foreach (var effect in tower.Effects)
                {
                    if (_.GetEffectTag(effect) == "CONTROL_TOWER_OUT_OF_POWER")
                    {
                        _.RemoveEffect(tower.Object, effect);
                        outOfPowerWasRemoved = true;
                        break;
                    }
                }

                if (outOfPowerWasRemoved)
                {
                    var instances = NWModule.Get().Areas.Where(x => x.GetLocalString("PC_BASE_STRUCTURE_ID") == structureID.ToString());
                    foreach (var instance in instances)
                    {
                        BaseService.ToggleInstanceObjectPower(instance, true);
                    }
                }
            }


            // Reinforced mode fuel usage
            if (pcBase.IsInReinforcedMode)
            {
                pcBase.ReinforcedFuel--;

                if (pcBase.ReinforcedFuel <= 0)
                {
                    pcBase.ReinforcedFuel     = 0;
                    pcBase.IsInReinforcedMode = false;
                }
            }
            // Tower regeneration only happens if fueled.
            else if (pcBase.DateFuelEnds > DateTime.UtcNow)
            {
                pcBase.ShieldHP += 12 + 4 * structure.StructureBonus;
            }

            if (pcBase.ShieldHP > maxShieldHP)
            {
                pcBase.ShieldHP = maxShieldHP;
            }

            DataService.SubmitDataChange(pcBase, DatabaseActionType.Update);
        }
Пример #2
0
        public bool Run(params object[] args)
        {
            NWPlaceable oSite = NWPlaceable.Wrap(Object.OBJECT_SELF);
            NWPlayer    oPC   = NWPlayer.Wrap(_.GetLastAttacker(oSite.Object));
            int         constructionSiteID = _structure.GetConstructionSiteID(oSite);

            if (constructionSiteID <= 0)
            {
                oPC.FloatingText("You must select a blueprint before you can build.");
                oPC.ClearAllActions();
                return(true);
            }

            NWItem weapon     = NWItem.Wrap(_.GetLastWeaponUsed(oPC.Object));
            int    weaponType = weapon.BaseItemType;

            if (weaponType != BASE_ITEM_LIGHTHAMMER)
            {
                oPC.FloatingText("A hammer must be equipped to build this structure.");
                oPC.ClearAllActions();
                return(true);
            }

            // Offhand weapons don't contribute to building.
            if (weapon.Equals(oPC.LeftHand))
            {
                return(true);
            }

            if (!_structure.IsConstructionSiteValid(oSite))
            {
                oPC.FloatingText("Construction site is invalid. Please click the construction site to find out more.");
                oPC.ClearAllActions();
                return(true);
            }


            Data.Entities.ConstructionSite entity = _structure.GetConstructionSiteByID(constructionSiteID);


            if (weapon.CraftTierLevel < entity.StructureBlueprint.CraftTierLevel)
            {
                oPC.FloatingText("Your hammer cannot be used with this blueprint. (Required Tool Level: " + entity.StructureBlueprint.CraftTierLevel + ")");
                oPC.ClearAllActions();
                return(true);
            }

            int    rank          = _skill.GetPCSkill(oPC, SkillType.Construction).Rank;
            int    mangleChance  = CalculateMangleChance(oPC, entity.StructureBlueprint.Level, rank);
            bool   isMangle      = _random.Random(100) + 1 <= mangleChance;
            bool   foundResource = false;
            string updateMessage = "You lack the necessary resources...";

            int totalAmount = 0;

            foreach (ConstructionSiteComponent comp in entity.ConstructionSiteComponents)
            {
                if (comp.Quantity > 0 && !foundResource)
                {
                    NWItem item = NWItem.Wrap(_.GetItemPossessedBy(oPC.Object, comp.StructureComponent.Resref));
                    if (item.IsValid)
                    {
                        int reuseChance = isMangle ? 0 : _perk.GetPCPerkLevel(oPC, PerkType.ConservativeConstruction) * 2 + _perk.GetPCPerkLevel(oPC, PerkType.Lucky);
                        if (_random.Random(100) + 1 <= reuseChance)
                        {
                            oPC.SendMessage("You conserve a resource...");
                        }
                        else
                        {
                            item.ReduceItemStack();
                        }

                        if (isMangle)
                        {
                            oPC.SendMessage(_color.Red("You mangle a resource due to your lack of skill..."));
                            return(true);
                        }

                        string name = _item.GetNameByResref(comp.StructureComponent.Resref);
                        comp.Quantity--;
                        updateMessage = "You need " + comp.Quantity + " " + name + " to complete this project.";
                        foundResource = true;
                    }
                }
                totalAmount += comp.Quantity;
            }

            oPC.DelayCommand(() => oPC.SendMessage(updateMessage), 0.75f);

            if (totalAmount <= 0)
            {
                _structure.CompleteStructure(oSite);
            }
            else if (foundResource)
            {
                _structure.SaveChanges();
                _durability.RunItemDecay(oPC, weapon);

                if (entity.StructureBlueprint.GivesSkillXP)
                {
                    int xp = (int)_skill.CalculateSkillAdjustedXP(100, 0, rank);
                    _skill.GiveSkillXP(oPC, SkillType.Construction, xp);
                }

                // Speedy Builder - Grants haste for 8 seconds
                int hasteChance = _perk.GetPCPerkLevel(oPC, PerkType.SpeedyBuilder) * 10;

                if (hasteChance > 0)
                {
                    hasteChance += _perk.GetPCPerkLevel(oPC, PerkType.Lucky) * 2;
                }

                PlayerCharacter pcEntity = _player.GetPlayerEntity(oPC);
                if (pcEntity.BackgroundID == (int)BackgroundType.ConstructionBuilder)
                {
                    hasteChance += 10;
                }

                if (_random.Random(100) + 1 <= hasteChance)
                {
                    _.ApplyEffectToObject(DURATION_TYPE_TEMPORARY, _.EffectHaste(), oPC.Object, 8.0f);
                }
            }
            else
            {
                oPC.ClearAllActions();
            }
            return(true);
        }
Пример #3
0
        public bool Run(params object[] args)
        {
            NWPlaceable     tower       = Object.OBJECT_SELF;
            Guid            structureID = new Guid(tower.GetLocalString("PC_BASE_STRUCTURE_ID"));
            PCBaseStructure structure   = _data.Single <PCBaseStructure>(x => x.ID == structureID);
            int             maxShieldHP = _base.CalculateMaxShieldHP(structure);
            var             pcBase      = _data.Get <PCBase>(structure.PCBaseID);

            // Regular fuel usage
            if (DateTime.UtcNow >= pcBase.DateFuelEnds && pcBase.Fuel > 0)
            {
                pcBase.Fuel--;
                pcBase.DateFuelEnds = DateTime.UtcNow.AddMinutes(30);

                // If a player is manipulating fuel, look for a fuel item and reduce its stack size or destroy it
                NWPlaceable bay = tower.GetLocalObject("CONTROL_TOWER_FUEL_BAY");
                if (bay.IsValid)
                {
                    bool isStronidium = bay.GetLocalInt("CONTROL_TOWER_FUEL_TYPE") == TRUE;
                    if (!isStronidium)
                    {
                        NWItem fuel = _.GetFirstItemInInventory(bay.Object);

                        if (fuel.IsValid)
                        {
                            fuel.ReduceItemStack();
                        }
                    }
                }
            }

            // If completely out of power, show tower in red.
            if (pcBase.Fuel <= 0 && DateTime.UtcNow > pcBase.DateFuelEnds)
            {
                bool outOfPowerHasBeenApplied = false;
                foreach (var effect in tower.Effects)
                {
                    if (_.GetEffectTag(effect) == "CONTROL_TOWER_OUT_OF_POWER")
                    {
                        outOfPowerHasBeenApplied = true;
                        break;
                    }
                }

                if (!outOfPowerHasBeenApplied)
                {
                    Effect outOfPowerEffect = _.EffectVisualEffect(VFX_DUR_AURA_RED);
                    outOfPowerEffect = _.TagEffect(outOfPowerEffect, "CONTROL_TOWER_OUT_OF_POWER");
                    _.ApplyEffectToObject(DURATION_TYPE_PERMANENT, outOfPowerEffect, tower.Object);

                    var instances = NWModule.Get().Areas.Where(x => x.GetLocalString("PC_BASE_STRUCTURE_ID") == structureID.ToString());

                    foreach (var instance in instances)
                    {
                        _base.ToggleInstanceObjectPower(instance, false);
                    }
                }
            }
            else
            {
                bool outOfPowerWasRemoved = false;
                foreach (var effect in tower.Effects)
                {
                    if (_.GetEffectTag(effect) == "CONTROL_TOWER_OUT_OF_POWER")
                    {
                        _.RemoveEffect(tower.Object, effect);
                        outOfPowerWasRemoved = true;
                        break;
                    }
                }

                if (outOfPowerWasRemoved)
                {
                    var instances = NWModule.Get().Areas.Where(x => x.GetLocalString("PC_BASE_STRUCTURE_ID") == structureID.ToString());
                    foreach (var instance in instances)
                    {
                        _base.ToggleInstanceObjectPower(instance, true);
                    }
                }
            }


            // Reinforced mode fuel usage
            if (pcBase.IsInReinforcedMode)
            {
                pcBase.ReinforcedFuel--;

                if (pcBase.ReinforcedFuel <= 0)
                {
                    pcBase.ReinforcedFuel     = 0;
                    pcBase.IsInReinforcedMode = false;
                }
            }
            // Tower regeneration only happens if fueled.
            else if (pcBase.DateFuelEnds > DateTime.UtcNow)
            {
                pcBase.ShieldHP += 12 + 4 * structure.StructureBonus;
            }

            if (pcBase.ShieldHP > maxShieldHP)
            {
                pcBase.ShieldHP = maxShieldHP;
            }

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