Refers to the base structure of the game
Inheritance: MonoBehaviour
Beispiel #1
0
        public NWPlaceable SpawnStructure(NWArea area, Guid pcBaseStructureID)
        {
            PCBaseStructure pcStructure   = _data.Get <PCBaseStructure>(pcBaseStructureID);
            PCBase          pcBase        = _data.Get <PCBase>(pcStructure.PCBaseID);
            BaseStructure   baseStructure = _data.Get <BaseStructure>(pcStructure.BaseStructureID);
            var             exteriorStyle = _data.Get <BuildingStyle>(pcStructure.ExteriorStyleID);

            NWLocation location = _.Location(area.Object,
                                             _.Vector((float)pcStructure.LocationX, (float)pcStructure.LocationY, (float)pcStructure.LocationZ),
                                             (float)pcStructure.LocationOrientation);

            BaseStructureType structureType = (BaseStructureType)baseStructure.BaseStructureTypeID;
            string            resref        = baseStructure.PlaceableResref;

            List <AreaStructure> areaStructures = area.Data["BASE_SERVICE_STRUCTURES"];

            if (string.IsNullOrWhiteSpace(resref) &&
                structureType == BaseStructureType.Building)
            {
                resref = exteriorStyle.Resref;
            }

            NWPlaceable plc = (_.CreateObject(OBJECT_TYPE_PLACEABLE, resref, location));

            plc.SetLocalString("PC_BASE_STRUCTURE_ID", pcStructure.ID.ToString());
            plc.SetLocalInt("REQUIRES_BASE_POWER", baseStructure.RequiresBasePower ? 1 : 0);
            plc.SetLocalString("ORIGINAL_SCRIPT_CLOSED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_CLOSED));
            plc.SetLocalString("ORIGINAL_SCRIPT_DAMAGED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_DAMAGED));
            plc.SetLocalString("ORIGINAL_SCRIPT_DEATH", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_DEATH));
            plc.SetLocalString("ORIGINAL_SCRIPT_HEARTBEAT", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_HEARTBEAT));
            plc.SetLocalString("ORIGINAL_SCRIPT_INVENTORYDISTURBED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED));
            plc.SetLocalString("ORIGINAL_SCRIPT_LOCK", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_LOCK));
            plc.SetLocalString("ORIGINAL_SCRIPT_MELEEATTACKED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_MELEEATTACKED));
            plc.SetLocalString("ORIGINAL_SCRIPT_OPEN", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_OPEN));
            plc.SetLocalString("ORIGINAL_SCRIPT_SPELLCASTAT", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_SPELLCASTAT));
            plc.SetLocalString("ORIGINAL_SCRIPT_UNLOCK", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_UNLOCK));
            plc.SetLocalString("ORIGINAL_SCRIPT_USED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_USED));
            plc.SetLocalString("ORIGINAL_SCRIPT_USER_DEFINED_EVENT", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_USER_DEFINED_EVENT));
            plc.SetLocalString("ORIGINAL_SCRIPT_LEFT_CLICK", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_LEFT_CLICK));
            plc.SetLocalString("ORIGINAL_JAVA_SCRIPT_1", _.GetLocalString(plc.Object, "JAVA_SCRIPT_1"));

            NWPlaceable door = null;

            if (structureType == BaseStructureType.Building)
            {
                door = SpawnBuildingDoor(exteriorStyle.DoorRule, plc);
                areaStructures.Add(new AreaStructure(pcStructure.PCBaseID, pcStructure.ID, door, false, null));
            }
            areaStructures.Add(new AreaStructure(pcStructure.PCBaseID, pcStructure.ID, plc, true, door));

            if (area.IsInstance && area.GetLocalInt("PC_BASE_STRUCTURE_ID") > 0)
            {
                if (DateTime.UtcNow > pcBase.DateFuelEnds && pcBase.Fuel <= 0)
                {
                    ToggleInstanceObjectPower(area, false);
                }
            }

            return(plc);
        }
Beispiel #2
0
        public GMacStructureBinding BindMemberToPattern(string memberName, IGMacTypedBinding pattern)
        {
            var dataMember = BaseStructure.DataMember(memberName);

            if (dataMember.IsNullOrInvalid())
            {
                throw new KeyNotFoundException("Structure data member " + memberName + " not found");
            }

            if (dataMember.AssociatedDataMember.HasSameType(pattern.GMacType.AssociatedType) == false)
            {
                throw new InvalidOperationException(
                          $"Can't bind structure data member {dataMember.AccessName} of type {dataMember.GMacTypeSignature} to pattern of type {pattern.GMacType.GMacTypeSignature}"
                          );
            }

            if (_patternDictionary.ContainsKey(memberName))
            {
                _patternDictionary[memberName] = pattern;
            }

            else
            {
                _patternDictionary.Add(memberName, pattern);
            }

            return(this);
        }
Beispiel #3
0
        public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData)
        {
            NWArea   area          = user.Area;
            NWPlayer player        = new NWPlayer(user);
            string   structureID   = area.GetLocalString("PC_BASE_STRUCTURE_ID");
            Guid     structureGuid = new Guid(structureID);

            PCBaseStructure pcbs      = DataService.PCBaseStructure.GetByID(structureGuid);
            BaseStructure   structure = DataService.BaseStructure.GetByID(pcbs.BaseStructureID);

            int repair    = SkillService.GetPCSkillRank(player, SkillType.Piloting);
            int maxRepair = (int)structure.Durability - (int)pcbs.Durability;

            if (maxRepair < repair)
            {
                repair = maxRepair;
            }

            // TODO - add perks to make repairing faster/better/shinier/etc.
            // Maybe a perk to allow repairing in space, with ground repairs only otherwise?

            NWCreature ship = area.GetLocalObject("CREATURE");

            if (ship.IsValid)
            {
                ship.SetLocalInt("HP", ship.GetLocalInt("HP") + repair);
                ship.FloatingText("Hull repaired: " + ship.GetLocalInt("HP") + "/" + ship.MaxHP);
            }

            pcbs.Durability += repair;
            DataService.SubmitDataChange(pcbs, DatabaseActionType.Update);

            player.SendMessage("Ship repaired for " + repair + " points. (Hull points: " + pcbs.Durability + "/" + structure.Durability + ")");
        }
 /// <summary>
 /// Display the object in Tree View
 /// </summary>
 /// <param name="obj">The object to display</param>
 /// <param name="RopNameforBinaryStructure">The string value used to as the name of tree node for object which is bianry value</param>
 public void DisplayObject(object obj, string RopNameforBinaryStructure)
 {
     if (obj == null)
     {
         return;
     }
     else if (obj.GetType().Name == "String")
     {
         this.FSSHTTPandWOPIViewControl.BeginUpdate();
         this.FSSHTTPandWOPIControl.FSSHTTPandWOPIRichTextBox.Visible = true;
         this.FSSHTTPandWOPIControl.FSSHTTPandWOPIRichTextBox.Text    = obj.ToString();
         this.FSSHTTPandWOPIViewControl.EndUpdate();
     }
     else
     {
         this.FSSHTTPandWOPIViewControl.BeginUpdate();
         TreeNode topNode = BaseStructure.ObjectToTreeNode(obj, RopNameforBinaryStructure);
         topNode = BaseStructure.RemoveAnySpecifiedTreeNode(topNode);
         int index = 1;
         topNode = BaseStructure.AddserialNumForFSSHTTPBTreeNode(topNode, ref index);
         this.FSSHTTPandWOPIViewControl.Nodes.Add(topNode);
         this.FSSHTTPandWOPIViewControl.Nodes[this.FSSHTTPandWOPIViewControl.Nodes.Count - 1].EnsureVisible();
         topNode.ExpandAll();
         this.FSSHTTPandWOPIViewControl.EndUpdate();
     }
 }
Beispiel #5
0
        public string IsValidTarget(NWCreature user, NWItem item, NWObject target, Location targetLocation)
        {
            NWArea area = user.Area;

            if (area.GetLocalInt("BUILDING_TYPE") != (int)Enumeration.BuildingType.Starship)
            {
                return("This repair kit may only be used inside a starship");
            }

            string structureID   = area.GetLocalString("PC_BASE_STRUCTURE_ID");
            Guid   structureGuid = new Guid(structureID);

            PCBaseStructure pcbs      = DataService.PCBaseStructure.GetByID(structureGuid);
            BaseStructure   structure = DataService.BaseStructure.GetByID(pcbs.BaseStructureID);

            if (structure.Durability == pcbs.Durability)
            {
                return("This starship is already fully repaired.");
            }

            bool   canRepair = (PerkService.GetCreaturePerkLevel(new NWPlayer(user), PerkType.CombatRepair) >= 1);
            PCBase pcBase    = DataService.PCBase.GetByID(pcbs.PCBaseID);

            if (!canRepair && SpaceService.IsLocationSpace(pcBase.ShipLocation))
            {
                return("You need the Combat Repair perk to repair ships in space.");
            }

            return("");
        }
Beispiel #6
0
 public void SetGhostStructure()
 {
     Destroy(ghostStructure.gameObject);
     ghostStructure = Instantiate(buildingPrefabs[prefabIdx]).GetComponent <BaseStructure>();
     UIManager.Instance.SetNameText(ghostStructure.structureName);
     UIManager.Instance.SetCostText((int)ghostStructure.energyCost);
 }
Beispiel #7
0
    public void Undo()
    {
        if (index <= -1)
        {
            return;
        }
        State args = stageData.states[index];

        if (args.state_type == "comment")
        {
            index--;
            return;
        }

        JObject stateDef = args.state_def;
        string  id       = (string)stateDef["id"];

        ChangeComments(" ");
        string funcType = args.state_type.Split('_').ToList()[1];

        if (funcType == "declare")
        {
            idToPlaceholderMap[id].SetActive(false);
        }

        BaseStructure currStructure = stageData.objectMap[id];

        currStructure.Undo(args);
        index--;
    }
        public void SetChoices(BaseStructure structure1, BaseStructure structure2)
        {
            CurrentSelectionModeState = SelectionMode.Double;

            towerType1 = structure1.GetType();
            towerType2 = structure2.GetType();

            StructureChoice1.DisplayChoice(structure1);
            StructureChoice2.DisplayChoice(structure2);

            StructureChoice1.HasEvents            = true;
            StructureChoice1.ExposeChildrenEvents = false;

            StructureChoice2.HasEvents            = true;
            StructureChoice2.ExposeChildrenEvents = false;

            structure1.X             = StructureChoice1.X;
            structure1.Y             = StructureChoice1.Y - 260;
            structure1.Z             = 2;
            structure1.IsBeingPlaced = false;

            structure2.X             = StructureChoice2.X;
            structure2.Y             = StructureChoice2.Y - 260;
            structure2.Z             = 2;
            structure2.IsBeingPlaced = false;

            StructureChoice1.Click += StructureChoice1_Click;
            StructureChoice2.Click += StructureChoice2_Click;

            ConfirmButton.Click += (unused) => ConfirmTowerSelection?.Invoke(this);
        }
 public void OnBuildFindTarget(BaseStructure building)
 {
     if (Vector3.Distance(building.transform.position, transform.position) < distFromTarget)
     {
         target_Current = building.transform;
         dir            = (building.transform.position - transform.position).normalized;
     }
 }
Beispiel #10
0
    public void DestroyStructure(BaseStructure structure)
    {
        structure.DisconnectNeighbors();
        structures.Remove(structure);
        connectors.Remove(structure);
        generators.Remove(structure);
        guns.Remove(structure);

        Destroy(structure.gameObject);
    }
        public static void LearnMaxTowerValues(BaseStructure tower)
        {
            //These are factored to account for tower upgrades
            _maxDamage          = Math.Max(_maxDamage, tower.AttackDamage * 1.5);
            _maxRange           = Math.Max(_maxRange, tower.RangedRadius * 1.5);
            _maxProjectileSpeed = Math.Max(_maxProjectileSpeed, tower.ProjectileSpeed * 1.5);

            //These are left unaltered because the values can only go down
            _maxMinRange             = Math.Max(_maxMinRange, tower.MinimumRangeRadius);
            _maxSecondsBetweenFiring = Math.Max(_maxSecondsBetweenFiring, tower.SecondsBetweenFiring);
        }
Beispiel #12
0
 public void UpdateGoal(IEnumerable <BaseStructure> baseStructures)
 {
     if (baseStructures.Count() > 0)
     {
         Goal = baseStructures.First();
     }
     else
     {
         Debug.Log("COLLECTOR :: No new goals.");
     }
 }
Beispiel #13
0
 public StructureInfoSaveState(BaseStructure structure)
 {
     this.StructureName    = structure.DisplayName;
     this.AttackDamageType = structure.AttackDamage.ToString();
     this.MinRange         = structure.MinimumRangeRadius.ToString();
     this.MaxRange         = structure.RangedRadius.ToString();
     this.AttackSpeed      = structure.SecondsBetweenFiring.ToString() + " sec";
     this.PointOrSplash    = structure.HasSplashDamage ? "Group" : "Single";
     SatoshiCost           = structure.SatoshiCost;
     SatoshiCostString     = structure.SatoshiCost.ToString();
     this.TowerType        = structure.GetType();
 }
 private static void CurrentTowersToInput(ref List <double> inputList, List <BaseStructure> towerList)
 {
     for (var i = 0; i < MaxTowers; i++)
     {
         BaseStructure tower = null;
         if (i < towerList.Count - 1)
         {
             tower = towerList[i];
         }
         inputList.AddRange(TowerToInput(tower));
     }
 }
Beispiel #15
0
 void StructuresInsideCircle()
 {
     Collider[] hitColliders = Physics.OverlapSphere(cityCenter, radius);
     foreach (Collider col in hitColliders)
     {
         BaseStructure structure = col.gameObject.GetComponent <BaseStructure> ();
         if (structure != null)
         {
             structuresWithinReach.Add(structure);
         }
     }
 }
Beispiel #16
0
 public void Show(BaseStructure structure, int currentSatoshis, bool allowUpgrade)
 {
     if (structure == structureShown)
     {
         Visible = true;
         structure.RangePreviewSprite.Visible = true;
     }
     else
     {
         Hide();
         SetDisplayFor(structure, currentSatoshis, allowUpgrade);
     }
 }
        public void GetByID_OneItem_ReturnsBaseStructure()
        {
            // Arrange
            BaseStructure entity = new BaseStructure {
                ID = 1
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <BaseStructure>(entity));

            // Assert
            Assert.AreNotSame(entity, _cache.GetByID(1));
        }
Beispiel #18
0
        private void ShowRangePreview(Tuple <int, int> rangeTuple, float xOffset, float yOffset)
        {
            if (CurrentPlacement == null)
            {
                return;
            }

            var rangeTexture = BaseStructure.GetRangeTexture(rangeTuple);

            CurrentPlacement.RangePreviewSprite.Texture   = rangeTexture;
            CurrentPlacement.RangePreviewSprite.RelativeX = xOffset;
            CurrentPlacement.RangePreviewSprite.RelativeY = yOffset;
            CurrentPlacement.RangePreviewSprite.Visible   = true;
        }
Beispiel #19
0
        public void Hide()
        {
            if (UpgradeInfoInstance.PulseAnimation.IsPlaying())
            {
                UpgradeInfoInstance.PulseAnimation.Stop();
            }

            if (structureShown != null)
            {
                structureShown.RangePreviewSprite.Visible = false;
            }
            structureSaveShown = null;
            structureShown     = null;
            Visible            = false;
        }
Beispiel #20
0
    public void ConnectToStructure(BaseStructure other, bool initiator = true)
    {
        connections.Add(other);
        if (initiator)
        {
            other.ConnectToStructure(this, false);

            if (lr != null)
            {
                lr.positionCount += 2;
                lr.SetPosition(lr.positionCount - 2, transform.position);
                lr.SetPosition(lr.positionCount - 1, other.transform.position);
            }
        }
    }
        private static IEnumerable <double> TowerToInput(BaseStructure tower)
        {
            if (tower != null)
            {
                var relativeTowerDamage = tower.AttackDamage / _maxDamage;

                return(new List <double>
                {
                    AbsoluteXCoordinateToRelative(tower.X),
                    //AbsoluteYCoordinateToRelative(tower.Y),
                    (tower.IsPiercing ? 0 : 1) * relativeTowerDamage,
                    (tower.IsBombarding ? 0 : 1) * relativeTowerDamage,
                    (tower.IsChemical ? 0 : 1) * relativeTowerDamage,
                    (tower.IsFrost ? 0 : 1) * relativeTowerDamage,
                    (tower.IsFire ? 0 : 1) * relativeTowerDamage,
                    (tower.IsElectrical ? 0 : 1) * relativeTowerDamage,
                    tower.RangedRadius / _maxRange,
                    tower.MinimumRangeRadius / _maxMinRange,
                    tower.SecondsBetweenFiring / _maxSecondsBetweenFiring,
                    tower.ProjectileSpeed / _maxProjectileSpeed,
                    //tower.HasSplashDamage ? 1.0 : 0.0,
                    //tower.SlowsEnemies ? 1.0 : 0.0,
                    //tower.StunsEnemies ? 1.0 : 0.0
                });
            }
            else
            {
                //Empty valued list
                return(new List <double>
                {
                    //0.0,
                    //0.0,
                    //0.0,
                    //0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                    0.0,
                });
            }
        }
Beispiel #22
0
    public void DisconnectFrom(BaseStructure other)
    {
        connections.Remove(other);

        if (lr != null)
        {
            lr.positionCount = 0;

            foreach (BaseStructure strct in connections)
            {
                lr.positionCount += 2;
                lr.SetPosition(lr.positionCount - 2, transform.position);
                lr.SetPosition(lr.positionCount - 1, strct.transform.position);
            }
        }
    }
Beispiel #23
0
        private string GetPlaceableResref(BaseStructure structure)
        {
            var    data   = BaseService.GetPlayerTempData(GetPC());
            string resref = structure.PlaceableResref;

            if (string.IsNullOrWhiteSpace(resref) &&
                structure.BaseStructureTypeID == (int)BaseStructureType.Building)
            {
                int exteriorID = data.StructureItem.GetLocalInt("STRUCTURE_BUILDING_EXTERIOR_ID");
                var style      = DataService.BuildingStyle.GetByID(exteriorID);

                resref = style.Resref;
            }

            return(resref);
        }
Beispiel #24
0
    public bool CanPlaceStructure(Transform obj)
    {
        BaseStructure closest = GetClosestStructure(obj.position);

        if (Vector3.Distance(obj.position, closest.transform.position) <= closest.personalSpace)
        {
            return(false);
        }

        closest = GetClosestConnector(obj.position);
        if (Vector3.Distance(obj.position, closest.transform.position) >= connectorReach)
        {
            return(false);
        }

        return(true);
    }
Beispiel #25
0
        public void ApplyCraftedItemLocalVariables(NWItem item, BaseStructure structure)
        {
            // Structure items need an additional local variable and their name set on creation.
            if (structure != null)
            {
                item.SetLocalInt("BASE_STRUCTURE_ID", structure.ID);
                item.Name = structure.Name;

                if (structure.BaseStructureTypeID == (int)BaseStructureType.Building)
                {
                    var defaultInterior = _data.Single <BuildingStyle>(x => x.BaseStructureID == structure.ID && x.IsDefault && x.BuildingTypeID == (int)BuildingType.Interior && x.IsActive).ID;
                    var defaultExterior = _data.Single <BuildingStyle>(x => x.BaseStructureID == structure.ID && x.IsDefault && x.BuildingTypeID == (int)BuildingType.Exterior && x.IsActive).ID;

                    item.SetLocalInt("STRUCTURE_BUILDING_INTERIOR_ID", defaultInterior);
                    item.SetLocalInt("STRUCTURE_BUILDING_EXTERIOR_ID", defaultExterior);
                }
            }
        }
Beispiel #26
0
        public void DisplayChoice(BaseStructure structure)
        {
            structureShown = structure;

            structureShown.RangePreviewSprite.Visible = false;
            StructureName = structureShown.DisplayName;
            SatoshiCost   = structureShown.SatoshiCost.ToString();
            AttackDamageType.ResistanceText = structure.AttackDamage.ToString();
            MinRange.AttributeText          = structure.MinimumRangeRadius.ToString();
            MaxRange.AttributeText          = structure.RangedRadius.ToString();
            AttackSpeed.AttributeText       = structure.SecondsBetweenFiring.ToString() + " sec";
            PointOrSplash.AttributeText     = structure.HasSplashDamage ? "Group" : "Single";
            SetIcon(structure.GetType());

            CurrentUpgradeAvailabilityState = UpgradeAvailability.NotAvailable;

            CurrentCostInfoState = CostInfo.Shown;
        }
Beispiel #27
0
    public BaseStructure GetClosestConnector(Vector3 pos)
    {
        BaseStructure ret     = null;
        float         minDist = float.MaxValue;
        float         thisDist;

        foreach (BaseStructure strct in connectors)
        {
            thisDist = Vector3.Distance(strct.transform.position, pos);
            if (thisDist < minDist)
            {
                ret     = strct;
                minDist = thisDist;
            }
        }

        return(ret);
    }
        public void GetByID_TwoItems_ReturnsCorrectObject()
        {
            // Arrange
            BaseStructure entity1 = new BaseStructure {
                ID = 1
            };
            BaseStructure entity2 = new BaseStructure {
                ID = 2
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <BaseStructure>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectSet <BaseStructure>(entity2));

            // Assert
            Assert.AreNotSame(entity1, _cache.GetByID(1));
            Assert.AreNotSame(entity2, _cache.GetByID(2));
        }
        public void GetByID_RemovedItem_ReturnsCorrectObject()
        {
            // Arrange
            BaseStructure entity1 = new BaseStructure {
                ID = 1
            };
            BaseStructure entity2 = new BaseStructure {
                ID = 2
            };

            // Act
            MessageHub.Instance.Publish(new OnCacheObjectSet <BaseStructure>(entity1));
            MessageHub.Instance.Publish(new OnCacheObjectSet <BaseStructure>(entity2));
            MessageHub.Instance.Publish(new OnCacheObjectDeleted <BaseStructure>(entity1));

            // Assert
            Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(1); });
            Assert.AreNotSame(entity2, _cache.GetByID(2));
        }
    private void BuildStructure()
    {
        BaseStructure structure = Instantiate <BaseStructure> (StructurePrefab);

        structure.transform.position = transform.position;
        Destroy(tempPrefab.gameObject);
        tempPrefab = null;

        BuildModeOverlay overlay = FindObjectsOfType <BuildModeOverlay>().FirstOrDefault(b => b.Builder == this);

        if (overlay != null)
        {
            overlay.Hide();
        }
        else
        {
            Debug.Log("Cannot find overlay for the builder!", this);
        }
    }