void Build(BuildableObject obj) { if (hudState != HUDState.BASE) { return; } BuildableObject planner = Instantiate(obj) as BuildableObject; // Will position itself automatically Debug.Log(obj.m_costToBuild.ToString()); if (!SummonerInventory.Instance.checkResourcesAvailable(planner.m_costToBuild)) { Destroy(planner.gameObject); return; } hudState = HUDState.BUILD; if (!mouse.BeginBuild(planner)) { Destroy(planner.gameObject); ResetHUDState(); return; } RefreshHUDSDisplay(); }
public float BuildingComplete(int level) { if (!_isSet) { SetUpComponent(); } //Set new structure sprite if (level == 1) { this.transform.GetComponent <SpriteRenderer>().sprite = _builtSpriteLevel1; } else if (level == 2) { this.transform.GetComponent <SpriteRenderer>().sprite = _builtSpriteLevel2; } else if (level == 3) { this.transform.GetComponent <SpriteRenderer>().sprite = _builtSpriteLevel3; } //increment Population Capacity //Note: its okay that this is called again when Loading Save Data, becuz the save data gets called after and overwrites it thankfully BuildableObject scr = GetComponent <BuildableObject>(); if (scr) { if (scr.getTeam() == 1) { ResourceManagerScript.Instance.incrementPopulationCapacity(capacityIncrementAmount[level] - capacityIncrementAmount[level - 1]); } } return(_hitpoints + (_hitPointGrowth * level)); }
public static GameObject Register(ModdedObject ModdedObject) { Debug.Log("=[HPRegistar]======(Registering: " + ModdedObject.Name + " = Type: " + ModdedObject.GetType() + ")===="); try { GameObject asset = ModdedObject.Object; if (asset == null) { asset = new GameObject(); } ModdedObject.Decorate(); Object.DontDestroyOnLoad(asset); BuildableObject buildableObject = asset.GetComponent <BuildableObject>(); buildableObject.dontSerialize = true; buildableObject.isPreview = true; asset.transform.parent = _hider.transform; AssetManager.Instance.registerObject(buildableObject); Debug.Log("=[HPRegistar]======(Succelfully Registering: " + ModdedObject.Name + ")===="); return(asset); } catch (System.Exception e) { Debug.Log("=[HPRegistar]======(Error)==[" + e + "]=="); return(null); } }
public void ShowDestroyMenu(bool cond, Vector3 loc, GameObject go, BuildableObject building) { if (_DestroyMenu) { _DestroyMenu.showMenu(cond, loc, go, building); } }
private void TryConnectPivotToObject(BuildableObject _otherObject, PivotObject _pivot) { if (_otherObject) { ConnectPivotToObject(_otherObject, _pivot); } }
public static BuildableObject CheckForConnection(Vector2 _pos, GameObject _ignore = null, int _mask = ~0) { Collider2D[] hit = Physics2D.OverlapPointAll(_pos, _mask); if (hit.Length == 0) { return(null); } //Get the front most buildable object (which isn't this one) BuildableObject otherObj = hit.Where(h => h.gameObject.GetComponent <BuildableObject>() != null && (_ignore == null || h.gameObject != _ignore && !h.transform.IsChildOf(_ignore.transform))) .Select(h => h.gameObject.GetComponent <BuildableObject>()) .OrderByDescending(bo => bo.selectionPriority) .FirstOrDefault(); // Collider2D otherCol = hit.FirstOrDefault(o => o.gameObject != gameObject && o.GetComponent<BuildableObject>() != null); // if (!otherCol) { return; } // BuildableObject otherObj = otherCol.gameObject.GetComponent<BuildableObject>(); return(otherObj); // print("Connecting " + gameObject + " to " + otherObj.gameObject); // ConnectToObject(otherObj); }
public override void Decorate(GameObject go, GameObject hider, ParkitectObj parkitectObj, AssetBundle bundle) { BuildableObject component = go.GetComponent <BuildableObject>(); component.price = Price; component.setDisplayName(InGameName); }
public void RemoveOutpost(BuildableObject outpost) { if (_outposts.Contains(outpost)) { _outposts.Remove(outpost); } }
// Start is called before the first frame update void Start() { currentBuildableObject = buildables[0]; world = FindObjectOfType <WorldManager>(); world.Money = 1000f; }
// Start is called before the first frame update void Start() { Transform t = this.transform.parent; if (t) { //Debug.Log("Found parent"); _ws = t.GetComponentInChildren <bWorkerScript>(); if (_ws) { // Debug.Log("Found WS"); GameObject go = _ws.getOwner(); if (go) { _bo = go.GetComponent <BuildableObject>(); } else { // bWorker hasn't finished its start setup, need delay StartCoroutine(ReSetup()); // Debug.Log("ReSetup"); } FigureOutMode(); } else { //Debug.Log("Cant find ws in children so Resetup2"); StartCoroutine(ReSetup2()); } } }
IEnumerator ReSetup2() { yield return(new WaitForSeconds(1f)); Transform t = this.transform.parent; if (t) { // Debug.Log("Found parent"); _ws = t.GetComponentInChildren <bWorkerScript>(); if (_ws) { // Debug.Log("Found WS"); GameObject go = _ws.getOwner(); if (go) { _bo = go.GetComponent <BuildableObject>(); } else { // bWorker hasn't finished its start setup, need delay StartCoroutine(ReSetup()); //Debug.Log("ReSetup"); } FigureOutMode(); } } }
public void LoadBumperCars() { GameObject asset = LoadAsset("BumperCars"); BumperCars.BumperCars bumperCars = asset.AddComponent <BumperCars.BumperCars>(); SetColors(asset, new[] { ConvertColor(161, 1, 1), ConvertColor(220, 205, 7), ConvertColor(112, 112, 112), ConvertColor(76, 76, 76) }); BasicFlatRideSettings(bumperCars, "Dodgems", 600, .75f, .3f, .1f, 6, 6); SetWaypoints(asset); asset.transform.position = new Vector3(0, 999, 0); BuildableObject buildableObject = asset.GetComponent <BuildableObject>(); buildableObject.dontSerialize = true; buildableObject.isPreview = true; AssetManager.Instance.registerObject(asset.GetComponent <FlatRide>()); }
public void SetOutpost(BuildableObject outpost) { if (!_outposts.Contains(outpost)) { _outposts.Add(outpost); } }
public void LoadData() { if (!_isStarted) { LoadImmediate(); LoadData(); } else { //Debug.Log("BeginLoad"); sBuildingData data = sSaveSystem.LoadBuildingData(); int[] IDs = data._IDs; for (int i = 0; i < data._IDs.Length; ++i) { int id = IDs[i]; BuildableObject b = _hashTable[id]; // Debug.Log("Loading for:" + b + " with hp=" + data._hp[i]); if (b) { b.LoadData(data._IDs[i], data._Type[i], data._State[i], data._level[i], data._hp[i], data._hpMax[i]); } else { Debug.LogError("ID:" + id + " was not present in the dictionary"); }; } } }
public void defenderBehavior() { Vector3 targetPos; // Check which side of the map the rodent is on if (currentTarget.transform.position.x - townCenterLoc.transform.position.x < 0) { targetPos = new Vector3(currentTarget.transform.position.x + 5, this.transform.position.y, 0); } else { targetPos = new Vector3(currentTarget.transform.position.x - 5, this.transform.position.y, 0); } if (!ShouldIdle) { // Skip this if ranger with an enemy as a target if (isRanged && Mathf.Abs(transform.position.x - currentTarget.transform.position.x) < 10f) { BuildableObject b = currentTarget.GetComponent <BuildableObject>(); if (team == 1 && currentTarget.tag == "Player") { // Do nothing if Allied and targetting king } else if (b) { if (currentTarget.GetComponent <BuildableObject>().getTeam() == team) { //do nothing } //Seems like we could use an else here to shoot, but when would a defender // have an enemy building in his agro list? shouldnt happen } else if (currentTarget.GetComponent <PlayerMovement>()) { if (currentTarget.GetComponent <PlayerMovement>().getInGround() == false) { StartCoroutine(Shoot(currentTarget.transform.position)); } else { _inRange.Remove(currentTarget); FindNextTargetInRange(); } } else { StartCoroutine(Shoot(currentTarget.transform.position)); } } else { Move(targetPos); } } // Maybe don't include idle so they seem more attentive at the wall? // Wait 15 units behind the wall they're assigned to }
void Start() { setUpMenu(); if (_onBuilding && _onPlayer) { Debug.LogWarning("This Worker script is set to be on both Player and Building, should only be one or the other"); } figureOutOwner(); if (_owner == null) { Debug.LogError("Owner of bWorkerScript is null :: " + this.transform.gameObject); } if (_onBuilding && _owner) { bo = _owner.GetComponent <BuildableObject>(); } else if (_onPlayer && _owner) { ps = _owner.GetComponent <PlayerStats>(); } if (bo) { col = this.GetComponent <CircleCollider2D>(); } if (ps) { col = this.GetComponent <BoxCollider2D>(); } }
public void LoadData(int id, int team, int type, int WorkID, float xPos) { if (_ID != id) { Debug.LogWarning("Rodent IDs do not match, save data failure"); } //Set the Position this.transform.position = new Vector3(xPos, this.transform.position.y, 0); //Set the Team _Team = team; //Set the Species setRodentType((eRodentType)type); //Figure out place of employment if (WorkID == -1) { setTarget(null); } else if (WorkID == -2) // is a royal guard { GameObject player = GameObject.FindGameObjectWithTag("Player"); setTarget(player); player.GetComponent <PlayerStats>().AssignWorker(this); } else { BuildableObject b = BuildingSlotManager.Instance.getBuildingFromID(WorkID); setTarget(b.gameObject); b.AssignWorker(this); if (b == null) { Debug.LogWarning("Rodent should work at building but its null, Possible Save Game Corruption"); } } }
public void SetBuilding(BuildableObject bo) { if (buildableObject == null) { buildableObject = bo; } }
public bool EndBuild() { Destroy(toBuild.gameObject); toBuild = null; action = Action.IDLE; return(true); }
public override void ConnectPivotToObject(BuildableObject _otherObject, PivotObject _pivot) { base.ConnectPivotToObject(_otherObject, _pivot); joint = _otherObject.gameObject.AddComponent <FixedJoint2D>(); joint.connectedBody = rb; joint.anchor = _otherObject.transform.InverseTransformPoint(_pivot.transform.position); }
public void ChooseObject(GameObject template, BuildableObject buildable) { if (!isAnObjectSelected) { currentlySelectedObject = Instantiate(template, spawnPos, Quaternion.identity); currentlySelectedObject.GetComponent <TemplateScript>().buildableObject = buildable; isAnObjectSelected = true; } }
public bool BeginBuild(BuildableObject building) { if (!building) { return(false); } toBuild = building; return(true); }
public void RodentAssigned(Rodent r) { if (_printStatements) { Debug.Log("heard rodent Assigned " + _lastClicked + " is last clicked"); } //Might want to do some other checks, like the building state? if (_lastClicked) { BuildableObject _Building = _lastClicked.GetComponent <BuildableObject>(); if (_Building) { //Check if this building is occupied // if (_Building.CheckOccupied()) { //To-Do: //play negative sound? //No Longer able to check this way } // else // free to assign { //Rodent Things , status update etc //r.setTarget(_lastClicked); _Building.AssignWorker(r); clearLastClicked(); // Dont want menu to close so we can keep assigning in the mode //_AssignmentMenu.showMenu(false); //instead reset the buttons UIAssignmentMenu.Instance.ResetButtons(); } } else { if (_printStatements) { Debug.Log("Assign to PLayer"); } PlayerStats Player = _lastClicked.GetComponent <PlayerStats>(); if (Player) { Player.AssignWorker(r); //Need a check to see if he can be assigned // r.setTarget(_lastClicked); clearLastClicked(); UIAssignmentMenu.Instance.ResetButtons(); } } } }
public override void ConnectPivotToObject(BuildableObject _otherObject, PivotObject _pivot) { base.ConnectPivotToObject(_otherObject, _pivot); joint = _otherObject.gameObject.AddComponent <FixedJoint2D>(); joint.connectedBody = rb; joint.anchor = _otherObject.transform.InverseTransformPoint(_pivot.transform.position); joint.autoConfigureConnectedAnchor = false; joint.breakForce = breakingForce; }
void Initialize() { for (int i = 0; i < buildableObject.Length; i++) { BuildableObject cachedBuildableObject = buildableObject[i]; GridObject cachedGridObject = cachedBuildableObject.gridObject; cachedGridObject.Initialize(); cachedBuildableObject.gridHud.keyText.text = cachedBuildableObject.gridHud.inputKey.ToString(); } }
public bool AttemptBuildAt(Vector3 pos, BuildableObject blueprint) { int x = (int)pos.x; int y = (int)pos.y; if (Tiles[x, y] == null) { Tiles[x, y] = new TileInfo(); } ; // Debug.LogError($"{x}, {y}"); if (Tiles[x, y].BuiltObject != null) { return(false); } // else if (Money < blueprint.Cost) // { // return false; // } else { GameObject newObj = Instantiate(blueprint.Prefab); newObj.transform.position = new Vector3(x, y, 0); Tiles[x, y].BuiltObject = blueprint; Tiles[x, y].BuiltTransform = newObj.transform; Money -= blueprint.Cost; if (blueprint.Category == BuildableObject.BuildableCategory.Road) { Tiles[x, y].BuiltTransform.GetComponent <Road>().world = this; for (int rx = x - 3; rx <= x + 3; rx++) { for (int ry = y - 3; ry <= y + 3; ry++) { if (rx < 0 || rx >= Tiles.GetLength(0) || ry < 0 || ry >= Tiles.GetLength(1) || Tiles[rx, ry] == null) { } else if (Tiles[rx, ry].BuiltObject.Category == BuildableObject.BuildableCategory.Road) { Tiles[rx, ry].BuiltTransform.GetComponent <Road>().RefreshSprite(); } } } } else if (blueprint.Category == BuildableObject.BuildableCategory.House) { Houses.Add(Tiles[x, y].BuiltTransform.GetComponent <HouseScript>()); } else if (blueprint.Category == BuildableObject.BuildableCategory.Decoration) { DecorationTiles.Add(new Vector3(x, y, 0)); } return(true); } }
public virtual void ConnectPivotToObject(BuildableObject _otherObject, PivotObject _pivot) { if (_pivot.connectedBody) { DisconnectPivot(_pivot); } _pivot.connectedBody = _otherObject; spriteR.sortingOrder = selectionPriority = _otherObject.selectionPriority + 1; print("Connecting " + gameObject.name + " to " + _otherObject.gameObject.name); }
public override void ConnectPivotToObject(BuildableObject _otherObject, PivotObject _pivot) { base.ConnectPivotToObject(_otherObject, _pivot); _pivot.joint = _otherObject.gameObject.AddComponent <WheelJoint2D>(); WheelJoint2D wheelJoint = _pivot.joint as WheelJoint2D; wheelJoint.connectedBody = rb; wheelJoint.autoConfigureConnectedAnchor = false; wheelJoint.anchor = _otherObject.transform.InverseTransformPoint(_pivot.transform.position); wheelJoint.connectedAnchor = transform.InverseTransformPoint(_pivot.transform.position); }
public int GetBuildingCap() { if (_TownCenter) { BuildableObject bo = _TownCenter.transform.GetComponent <BuildableObject>(); if (bo) { return(bo.getLevel() * 4); } } Debug.LogWarning("No TownCenter"); return(0); }
public override void Decorate(GameObject go, GameObject hider, ParkitectObj parkitectObj, AssetBundle bundle) { BuildableObject buildableObject = go.GetComponent <BuildableObject>(); if (!String.IsNullOrEmpty(SubCategory)) { buildableObject.categoryTag = Category + "/" + SubCategory; } else { buildableObject.categoryTag = Category; } }
public BuildLogData(BuildableObject buildableObject, Planet planet) { this.buildableObject = buildableObject; this.planet = planet; }
public void AddRecord(BuildableObject buildableObject, Planet planet) { BuildLogData buildLogData = new BuildLogData(buildableObject, planet); buildLogDataEntries.Add(buildLogData); }