Exemplo n.º 1
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);
            }
        }