Exemple #1
0
        private void DoRotateConstructionSite(float rotation, bool isSet)
        {
            NWPlayer oPC   = GetPC();
            Model    model = GetDialogCustomData <Model>();

            if (!_structure.PlayerHasPermission(oPC, StructurePermission.CanRotateStructures, model.FlagID))
            {
                oPC.FloatingText("You do not have permission to rotate structures.");
                BuildMainPage();
                ChangePage("MainPage");
                return;
            }

            int constructionSiteID = _structure.GetConstructionSiteID((NWPlaceable)GetDialogTarget());

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

            if (isSet)
            {
                entity.LocationOrientation = rotation;
            }
            else
            {
                entity.LocationOrientation = entity.LocationOrientation + rotation;
            }

            _structure.SaveChanges();
            GetDialogTarget().Facing = (float)entity.LocationOrientation;
        }
Exemple #2
0
        private void HandleRotateStructure(float rotation, bool isSet)
        {
            NWPlayer oPC    = GetPC();
            Model    model  = GetDialogCustomData <Model>();
            int      flagID = _structure.GetTerritoryFlagID(model.Flag);

            if (!_structure.PlayerHasPermission(oPC, StructurePermission.CanRotateStructures, flagID))
            {
                _.FloatingTextStringOnCreature("You do not have permission to rotate this structure.", oPC.Object, FALSE);
                BuildMainMenuResponses(null);
                ChangePage("MainPage");
                return;
            }

            int structureID = _structure.GetPlaceableStructureID(model.ActiveStructure);
            PCTerritoryFlagsStructure entity = _structure.GetPCStructureByID(structureID);

            if (isSet)
            {
                entity.LocationOrientation = rotation;
            }
            else
            {
                double newOrientation = entity.LocationOrientation + rotation;
                while (newOrientation >= 360.0f)
                {
                    newOrientation -= 360.0f;
                }

                entity.LocationOrientation = newOrientation;
            }

            _structure.SaveChanges();

            NWPlaceable door    = NWPlaceable.Wrap(model.ActiveStructure.GetLocalObject("BUILDING_ENTRANCE_DOOR"));
            bool        hasDoor = door.IsValid;

            if (hasDoor)
            {
                door.Destroy();
            }

            NWPlaceable structure = model.ActiveStructure;

            structure.Facing = (float)entity.LocationOrientation;
            if (hasDoor)
            {
                NWPlaceable newDoor = _structure.CreateBuildingDoor(structure.Location, structureID);
                newDoor.SetLocalObject("BUILDING_DOOR_ENTRANCE", newDoor.Object);
            }
        }
        public bool Run(params object[] args)
        {
            NWPlayer    oPC         = NWPlayer.Wrap(_.GetLastDisturbed());
            NWItem      item        = NWItem.Wrap(_.GetInventoryDisturbItem());
            NWPlaceable container   = NWPlaceable.Wrap(Object.OBJECT_SELF);
            int         disturbType = _.GetInventoryDisturbType();

            int structureID = container.GetLocalInt("STRUCTURE_TEMP_STRUCTURE_ID");
            PCTerritoryFlagsStructure entity = _structure.GetPCStructureByID(structureID);
            int    itemCount  = container.InventoryItems.Count;
            string itemResref = item.Resref;

            if (disturbType == INVENTORY_DISTURB_TYPE_ADDED)
            {
                if (itemCount > entity.StructureBlueprint.ItemStorageCount)
                {
                    ReturnItem(oPC, item);
                    oPC.SendMessage(_color.Red("No more items can be placed inside."));
                }
                // Only specific types of items can be stored in resource bundles
                else if (!string.IsNullOrWhiteSpace(entity.StructureBlueprint.ResourceResref) && itemResref != entity.StructureBlueprint.ResourceResref)
                {
                    ReturnItem(oPC, item);
                    oPC.SendMessage(_color.Red("That item cannot be stored here."));
                }
                else
                {
                    PCTerritoryFlagsStructuresItem itemEntity = new PCTerritoryFlagsStructuresItem
                    {
                        ItemName      = item.Name,
                        ItemResref    = itemResref,
                        ItemTag       = item.Tag,
                        PCStructureID = entity.PCTerritoryFlagStructureID,
                        GlobalID      = item.GlobalID,
                        ItemObject    = _serialization.Serialize(item)
                    };

                    entity.PCTerritoryFlagsStructuresItems.Add(itemEntity);
                    _structure.SaveChanges();
                }
            }
            else if (disturbType == INVENTORY_DISTURB_TYPE_REMOVED)
            {
                _structure.DeleteContainerItemByGlobalID(item.GlobalID);
            }

            oPC.SendMessage(_color.White("Item Limit: " + itemCount + " / ") + _color.Red(entity.StructureBlueprint.ItemStorageCount.ToString()));

            return(true);
        }
Exemple #4
0
        private void ToggleOwnerName()
        {
            Model           model = GetDialogCustomData <Model>();
            PCTerritoryFlag flag  = _structure.GetPCTerritoryFlagByID(model.FlagID);

            flag.ShowOwnerName = !flag.ShowOwnerName;

            if (flag.ShowOwnerName)
            {
                PlayerCharacter owner = _player.GetPlayerEntity(flag.PlayerID);

                // Building
                if (model.FlagMarker == null)
                {
                    GetPC().FloatingText("Now displaying owner's name on this building.");
                }
                // Territory Marker
                else
                {
                    GetPC().FloatingText("Now displaying owner's name on this territory marker.");
                    model.FlagMarker.Name = owner.CharacterName + "'s Territory";
                }
            }
            else
            {
                if (model.FlagMarker == null)
                {
                    GetPC().FloatingText("No longer displaying owner's name on this building.");
                }
                else
                {
                    GetPC().FloatingText("No longer displaying owner's name on this territory marker.");
                    model.FlagMarker.Name = "Claimed Territory";
                }
            }

            _structure.SaveChanges();
            BuildMainPageHeader();
        }
Exemple #5
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);
        }