public Building(ObjectID id, BuildingData bd, Map map, Position pos, Simulation sim) : base(id, BoardObjectClass.Building, pos) { this._direction = Direction.North; this._buildingData = bd; this._map = map; this.state = BuildingState.constructing; this.Health = bd.__Health; this.roundToReload = 0; this._simulation = sim; String ammo = bd.AmmoType; if (ammo == "Bullet") { this.ammoType = AmmoType.Bullet; } else if (ammo == "Rocket") { this.ammoType = AmmoType.Rocket; } else if (ammo == "Sonic") { this.ammoType = AmmoType.Sonic; } else { this.ammoType = AmmoType.None; } }
void onStateChanged(BuildingState newstate) { var st = currentState; Close(); BuildingInfoUI.ShowUI(st.Building); }
/* * public void ClearFogOfWar() { * int viewRange = _buildingData.ViewRange; * * for (int x = -viewRange + Position.X; x <= viewRange + Position.X; x++) { * for (int y = -viewRange + Position.Y; y <= viewRange + Position.Y; y++) { * if (x < 0 || y < 0 || x > _map.Width - 1 || y > _map.Height - 1) { * continue; * } * _map.FogOfWar[x, y] = false; * } * } * } */ /// <summary> /// manage building /// there are buildings which can shoot - some ai /// </summary> public void DoAI() { if (_bStatus != null) { if (_bStatus.DoTurn()) { this.state = BuildingState.normal; } } if (this.State == BuildingState.normal) { if (this.BuildingData.FirePower == 0) { return; } if (roundToReload > 0) { // reload time - cant shoot. roundToReload--; return; } if (FindNearestTargetInFireRange(out attacked)) { /* * actions for looking for target, shooting * */ TryAttack(attacked); roundToReload = BuildingData.__ReloadTime; } } }
public bool CanBuild() { bool hasEnoughResources = false; List <ResourceAmount> resourceAmounts = new List <ResourceAmount>(); for (int i = 0; i < resourceCosts.Count; i++) { ResourceAmount currentAmount = Resource.Instance.GetResourceAmount(resourceCosts[i].resourceType); ResourceAmount cost = resourceCosts[i]; if (currentAmount.resourceAmount >= cost.resourceAmount) { resourceAmounts.Add(currentAmount); } } if (resourceAmounts.Count >= resourceCosts.Count) { hasEnoughResources = true; // resourceAmounts has the same order as resourceCosts for (int i = 0; i < resourceCosts.Count; i++) { resourceAmounts[i].resourceAmount -= resourceCosts[i].resourceAmount; } buildingState = BuildingState.Building; GameEvents.BuildingStarted(this); GameEvents.OnTimePassed += CheckBuildingTime; } return(hasEnoughResources); }
public override void Reset() { this.id = -1; this.towerTypeID = -1; mark = ForceMark.NoneForce; transform.position = Vector3.zero; position = FixVector3.zero; state = BuildingState.BUILD; buildCost = 0; maxHp = 0; attackArea = 0; attackInterval = 0; rangeDmgVar = 0; rangeDmgBase = 0; damage = 0; physicalResistance = 0; magicResistance = 0; recycleValue = 0; projectileId = 0; towerBuildTime = 0; towerBuildingTimer = 0; PostRenderMessage = null; PostDestroy = null; GetRandomNumber = null; PostBattleMessage = null; FindOpponentSoldier = null; FindOpponentDemolisher = null; FindOpponentCrystalCar = null; FindOpponentSoldiers = null; WithinCircleAreaPredicate = null; WithinFrontRectAreaPredicate = null; }
public void Initialize(long id, FixVector3 pos, FixVector3 rot, bool isPlusCrystal) { this.id = id; type = LogicUnitType.Crystal; state = BuildingState.IDLE; ownerMark = ForceMark.NoneForce; transform.position = pos.vector3; transform.eulerAngles = rot.vector3; position = pos; crystalPlus = isPlusCrystal; modelRadius = ConvertUtils.ToLogicInt(GameConstants.CRYSTAL_MODELRADIUS); if (isPlusCrystal) { modelId = GameConstants.CRYSTAL_BIG_RESOURCEID; maxHp = GameConstants.CRYSTAL_BIG_RESERVES; rebornTime = GameConstants.CRYSTAL_BIG_RECOVERTIME; } else { modelId = GameConstants.CRYSTAL_SMALL_RESOURCEID; maxHp = GameConstants.CRYSTAL_SMALL_RESERVES; rebornTime = GameConstants.CRYSTAL_SMALL_RECOVERTIME; } removeOwnerInterval = GameConstants.CRYSTAL_REMOVEOWNER_INTERVAL; hp = maxHp; }
public void BuildingUnlock() { buildingState = BuildingState.Unlocked; GameEvents.BuildingUnlocked(this); GameEvents.OnBuildingCompleted -= CheckBuildingRequirements; Debug.Log("Building unlocked " + buildingName); }
public virtual void OnStateChanged(BuildingState state) { foreach (var r in meshRenderers) { r.sharedMaterial = state.material; } }
// void ToHover() // { // if(SelectionController00.instance.currentState == SelectionState.Free) // SelectionController00.instance.currentState = SelectionState.OnBuild; // mainColor.a = 0.5f; // mainRend.material.color = mainColor; // currentState = BuildingState.Hover; // } // // void Hover() // { // if(Input.GetKeyDown(KeyCode.Escape) || Input.GetMouseButtonDown(1)) // { // if(SelectionController00.instance.currentState == SelectionState.OnBuild) // SelectionController00.instance.currentState = SelectionState.Free; // print("build cancel"); // Destroy(gameObject); // } // // Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // RaycastHit hit; // if(Physics.Raycast(ray, out hit, 100, 1 << 8)) // { // Vector3 snapPosition = new Vector3(Mathf.RoundToInt(hit.point.x), hit.point.y, Mathf.RoundToInt(hit.point.z)); // transform.position = snapPosition; // } // // if(Input.GetMouseButtonDown(0) && !invalidLocation) // { // ToPrepare(); // } // } void ToPrepare() { if (Selection.instance.currentState == SelectionState.OnBuild) { Selection.instance.currentState = SelectionState.Free; //Destroy(SelectionController00.instance.selectableEntities[0].ISelectTransform.gameObject); Selection.instance.selectableEntities.Clear(); UIController.instance.commandController.Clear(); } if (!isBuilderExist) { if (builder is VillagerCart) { VillagerCart cart = (VillagerCart)builder; cart.Build(this); } if (builder is Villager) { Villager villager = (Villager)builder; villager.Build(this); } } mainRend.material.color = Color.grey; obstacle.enabled = true; currentState = BuildingState.Prepare; }
public void changeState(BuildingState newState) { state = newState; if (newState == BuildingState.inConstruction) { GetComponent <SpriteRenderer> ().color = Color.green; canBuild = true; Component[] c = GetComponentsInChildren <CircleCollider2D> (); foreach (CircleCollider2D cc in c) { if (cc.name == "RangeRadius") { cc.enabled = false; } } } else { GetComponent <SpriteRenderer> ().color = Color.white; if (transform.GetChild(0).GetComponent <SpriteRenderer>() != null && GetComponent <IncomeBuilding>() == null) { transform.GetChild(0).GetComponent <SpriteRenderer>().enabled = false; } Component[] c = GetComponentsInChildren <CircleCollider2D> (); foreach (CircleCollider2D cc in c) { if (cc.name == "RangeRadius") { cc.enabled = true; } } } }
void FSM() { switch (m_curState) { case BuildingState.idle: break; case BuildingState.attacking: break; case BuildingState.switching: if (m_targetList.Count > 0) { m_curTarget = m_targetList[0]; m_curState = BuildingState.attacking; m_turret.SetTarget(m_curTarget.transform); } else { m_turret.Stop(); m_curState = BuildingState.idle; } break; } }
void SetState(BuildingState state) { State = state; switch (State) { case BuildingState.NotForSale: unselectedMaterial = notForSaleMaterial; break; case BuildingState.ForSale: unselectedMaterial = forSaleMaterial; break; case BuildingState.Unlivable: case BuildingState.Owned: unselectedMaterial = ownedMaterial; break; case BuildingState.Renovating: unselectedMaterial = renovatingMaterial; break; } if (!Selected) { buildingMesh.material = unselectedMaterial; } }
void UpdateUI(BuildingState state) { if (state == BuildingState.Ready || state == BuildingState.Leaving) { TurnBuildState(); } }
public void UpdateAttackState() { if (interacting) { if (State == BuildingState.UnderAttack) { Player player = GameController.instance.GetMetropolyPlayer(); player.myAudioSource.volume = 100; State = BuildingState.SavingFromAttack; attackBar.SetTimerBarAttack(attackSaveTime); showAttackBar(); attackCurrentTime += Time.deltaTime; attackBar.UpdateBar(); TryRemoveAttack(); } else if (State == BuildingState.SavingFromAttack) { attackCurrentTime += Time.deltaTime; attackBar.UpdateBar(); TryRemoveAttack(); } } else if (State == BuildingState.SavingFromAttack) { GameController.instance.GetMetropolyPlayer().myAudioSource.volume = 0; State = BuildingState.UnderAttack; ShowAttackIcon(); } }
private BuildingState FinishWritingScalarValue(BuildingState currentState) { switch (currentState.State) { case ContinuationState.ReadPropertyValue: currentState.Properties.Add(new PropertyTag { Position = _writeToken.ValuePos, Type = (byte)_writeToken.WrittenToken, Property = currentState.CurrentProperty }); currentState.State = ContinuationState.ReadPropertyName; break; case ContinuationState.ReadArray: currentState.Types.Add(_writeToken.WrittenToken); currentState.Positions.Add(_writeToken.ValuePos); break; default: ThrowIllegalStateException(currentState.State, "ReadValue"); break; } return(currentState); }
void Start() { Debug.Log("Stair: Start method"); _state = BuildingState.Building; _creationTime = Time.time; switch (_inclination) { case InclinationDirection.Up: _inclinationAngle = Mathf.PI / 4f; Debug.Log("Stair: " + Name + ", set - inclinationAngle: " + _inclinationAngle); break; case InclinationDirection.Down: _inclinationAngle = -1 * Mathf.PI / 4f; Debug.Log("Stair: " + Name + ", set - inclinationAngle: " + _inclinationAngle); break; } Quaternion rotation = Quaternion.LookRotation(_direction); rotation = rotation * Quaternion.LookRotation(new Vector3(0, Mathf.Sin(_inclinationAngle), Mathf.Cos(_inclinationAngle))); this.transform.rotation = rotation; this.transform.localScale = new Vector3(this.transform.localScale.x, this.transform.localScale.y, 0); }
public static void Postfix(InstanceState instanceState, ref Matrix4x4 matrix4x, float deltaAngle, Vector3 center, bool followTerrain) { BuildingState state = instanceState as BuildingState; Vector3 newPosition = matrix4x.MultiplyPoint(state.position - center); if (state.subStates != null) { foreach (InstanceState subState in state.subStates) { if (subState is BuildingState bs) { if (bs.subStates != null) { foreach (InstanceState subSubState in bs.subStates) { Vector3 subPosition = subSubState.position - center; subPosition = matrix4x.MultiplyPoint(subPosition); subPosition.y = subSubState.position.y - state.position.y + newPosition.y; subSubState.instance.Move(subPosition, subSubState.angle + deltaAngle); } } } } } }
private void OnEnable() { gameObject.name = Data.Name; SetPlacementMaterial(); BuildingGridBounds.EnableRenderers(); State = BuildingState.Placing; }
public void ResetOne() { if (reset_on_dead) { state = start_state; } }
public void IncrementConstruction(int amnt) { //increment construction safely if (amnt > 0) { if (_construction + amnt <= _constructionMax) { _construction += amnt; } else { _construction = _constructionMax; } } //check if construction is full, then complete building if (_construction >= _constructionMax) { BuildComplete(); //Do this here so when we load from save things dont get wonky eState = BuildingState.Built; UpdateState(); //kick builder rat off worker_obj dismissCurrentWorker(); } //update Gather Bar UpdateConstructionBar(); }
private void Build(float timePassed) { if (_state == BuildingState.Building) { //float timeBuilding = atTime - _creationTime; float bridgeGrowth = timePassed * _buildingSpeed; float oldBridgeLength = this.transform.localScale.z; float newBridgeLength = this.transform.localScale.z + bridgeGrowth; //if (WillBumpIntoSomething(bridgeLength)) //{ // State = BuildingState.Done; //} //else { if (newBridgeLength >= _bridgeMaxLength) { //bridgeLength = _bridgeMaxLength; newBridgeLength = _bridgeMaxLength; _state = BuildingState.Done; } float finalGrowth = newBridgeLength - oldBridgeLength; this.transform.position = Position + (_direction * finalGrowth / 2f); this.transform.localScale = new Vector3(this.transform.localScale.x, this.transform.localScale.y, newBridgeLength); } } //return State; }
public void BuildButton() { // Tutorial indicator // TutorialManager.instance.DisplayIndicator(TutorialManager.IndicatorID.click_on_build, false); TutorialManager.instance.DisplayIndicatorIfNotDisplayedYet(TutorialManager.IndicatorID.touch_building); // ------------------ // if (buildingState == BuildingState.LocationSelected || buildingState == BuildingState.BuildingAndLocationSelected) { if (chosenBuildingSlot.GetComponent <BuildingSlot>().CanBuildHere()) { if (ResourcesManager.instance.CanPayConstruction(selectedBuilding)) { ResourcesManager.instance.PayConstruction(selectedBuilding); BuildBuilding(); buildingState = BuildingState.Default; ShowBuildButton(false); BuildingSlotManager.instance.ResetAllBuildingSlotsColor(); SurroundingAreasManager.instance.ResetAllSatelliteBuildingSlotsColor(); //ShopPanel.instance.ResetLastShopItemSelected(); // TO REDO //Debug.Log("Building Placed | Leaving Building State."); // If building is Unique, disable corresponding ShopItem if (selectedBuilding.isUnique) { //ShopPanel.instance.GetShopItemAssociatedWithBuildingType(selectedBuilding).SetActive(false); // TO REDO } } } } GameManager.instance.ChangeSelectionState(GameManager.SelectionState.Default); }
public void DemolishComplete() { if (_Team == 1) { NotificationFeed.Instance.NewNotification("BUILDING DESTROYED!", "Your building was demolished!", 2, transform.position.x); } eState = BuildingState.Available; _sr.sprite = _sStatedefault; _construction = 0; _constructionMax = 5; UpdateConstructionBar(); _hitpointsMax = 5; _hitpoints = 0; if (_controller.getLastClicked() == this.gameObject) { _controller.clearLastClicked(); } ShowRedX(false); //Kick the worker rodent off dismissCurrentWorker(); //if we have returned to a dirt mount, reset team to default if (_level == 0) { setTeam(500); ResourceManagerScript.Instance.IncrementBuildingSlots(-1); //set sprite to dirt mound _sr.sprite = _sStatedefault; } }
public void ChangeState(BuildingState newState) { if (BState != newState) { BState = newState; } }
public BuildingUpdatePacket(GameLocation loc, Building b) : this() { location = loc.name; buildingId = b.nameOfIndoors; state = new BuildingState(b); }
private static void Day11() { var currentState = new BuildingState(new List <char> { 'P', 'T', 'Z', 'R', 'C', 'E', 'D' }); currentState.ElevatorLocation = 0; currentState.SetChipLocation('P', 1); currentState.SetGeneratorLocation('P', 0); currentState.SetChipLocation('T', 0); currentState.SetGeneratorLocation('T', 0); currentState.SetChipLocation('Z', 1); currentState.SetGeneratorLocation('Z', 0); currentState.SetChipLocation('R', 0); currentState.SetGeneratorLocation('R', 0); currentState.SetChipLocation('C', 0); currentState.SetGeneratorLocation('C', 0); currentState.SetChipLocation('E', 0); currentState.SetGeneratorLocation('E', 0); currentState.SetChipLocation('D', 0); currentState.SetGeneratorLocation('D', 0); var stateTraverser = new StateTraverser(); var goalState = BuildingState.CreateGoalState(currentState); var stepsToGoalState = stateTraverser.GetStepsToGoalState(currentState, goalState); Console.WriteLine("Steps: " + stepsToGoalState); }
public void SetState(BuildingState _state) { state = _state; switch (state) // TODO: попытаться избавиться от всех этих свитчей, мб как-то все в общий метод запихнуть? { case BuildingState.Normal: hp100.gameObject.SetActive(true); DisableCollider(); break; case BuildingState.HP75: cheapCost = Random.Range(40, 60); fullRepairCost = Random.Range(60, 80); hp75.gameObject.SetActive(true); break; case BuildingState.HP50: cheapCost = Random.Range(60, 80); fullRepairCost = Random.Range(80, 120); hp50.gameObject.SetActive(true); break; default: break; } }
public void Initialize() { buildingState = BuildingState.Default; mainPlanet = GameManager.instance.mainPlanet; ShowBuildButton(false); }
// Use this for initialization void Start() { Debug.Log("Bridge: Start method"); _state = BuildingState.Building; _creationTime = Time.time; this.transform.localScale = new Vector3(this.transform.localScale.x, this.transform.localScale.y, 0); }
//Temporary way to delay construction- UNUSED IEnumerator BuildCoroutine() { yield return(new WaitForSeconds(5f)); BuildComplete(); //Do this here so when we load from save things dont get wonky eState = BuildingState.Built; }
public virtual void SwitchToState(BuildingState state) { this.state = state; switch (this.state) { case BuildingState.BUILDING: this.SwitchToBuilding(); break; case BuildingState.IDLE: this.SwitchToIdle(); break; case BuildingState.DESTROYING: this.SwitchToDestroying(); break; case BuildingState.CUSTOM: this.SwitchToCustom(); break; } }
public virtual void OnMouseUp() { if (CurrentState == BuildingState.OnMouse) { // checks if player has enoguh to place the building if(Cost > SH_GameManager.GM.TotalResource) { Destroy(gameObject); return; } SH_GameManager.GM.TotalResource -= Cost; // places building in selected location CurrentState = BuildingState.Placed; SH_GameManager.GM.OccupiredGrids.Add(transform.position, gameObject); } }
/* * building has been pressed */ private void pressedHandler(object sender, EventArgs e) { //are we choosing building at the beginning of the game? if (state == BuildingState.Menu) { origin = Instantiate (gameObject) as GameObject; origin.transform.position = gameObject.transform.position; origin.transform.localScale = new Vector3(1,1,1); origin.transform.parent = gameObject.transform.parent; origin.SetActive (false); gameObject.transform.parent = null; } else { //check to see that the game is running properly var controller = GameObject.FindGameObjectWithTag (Tags.GameController); var clock = controller.GetComponent<Clock> (); if (clock == null) { Debug.LogError ("Oh shit no clock!"); } //building is built if (state == BuildingState.Built) { //create building menu if one doesn't exist if (menu == null){ GameObject obj = Instantiate (menuPrefab) as GameObject; obj.transform.position = gameObject.transform.position; obj.name = gameObject.name + "Menu"; obj.transform.parent = gameObject.transform; obj.GetComponent<Popup>().setTarget(gameObject); menu = obj; } //if one does exist destroy it else { Destroy (menu); menu = null; } } //if the building is in the pallet if (state == BuildingState.Pallet) { //create a copy of the building, but disable it's creation methods etc. var obj = Instantiate (gameObject) as GameObject; obj.name = (gameObject.name); obj.GetComponent<Cube> ().enabled = true; obj.GetComponent<TapGesture> ().enabled = true; obj.transform.parent = gameObject.transform.parent; obj.GetComponent<Cube>().setState (BuildingState.Pallet); var pos = obj.transform.position; pos.z = -3.0f; gameObject.transform.position = pos; state = BuildingState.Dragging; tag = Tags.Placing; //spend materials for building switch(obj.name){ case "City": clock.spendMaterial(buildings.City); break; case "Factory": clock.spendMaterial(buildings.Factory); break; case "Farm": clock.spendMaterial(buildings.Farm); break; case "Fishing": clock.spendMaterial(buildings.Fishing); break; case "Lumber": clock.spendMaterial(buildings.Lumber); break; case "Mine": clock.spendMaterial(buildings.Mine); break; case "Power": clock.spendMaterial(buildings.Power); break; case "School": clock.spendMaterial(buildings.School); break; } //create blueprint for the building GameObject newBlueprint = (GameObject)GameObject.Instantiate (blueprintPrefab, gameObject.transform.position, gameObject.transform.rotation); blueprint = newBlueprint.GetComponent<Blueprint> (); blueprint.setParent (this.gameObject); } } }
// Use this for initialization void Start() { this.gameObject.layer = 2; this.gameObject.tag = "Building"; this.id = _buildingID_++; this.state = BuildingState.PREBUILD; this._collider = this.GetComponent<Collider>(); this._collider.isTrigger = true; this._mouseController = GameObject.FindObjectOfType<MouseController>().GetComponent<MouseController>(); this._handController = GameObject.FindObjectOfType<HandController>().GetComponent<HandController>(); this._renderer = this.GetComponent<MeshRenderer>(); this._originalColor = this._renderer.material.color; }
public void setState(BuildingState newState) { state = newState; }
/* * called when a building is placed on the map */ private void releasedHandler(object sender, EventArgs e) { //used for selecting buildings at the beginning of the game if (state == BuildingState.Menu) { float x = gameObject.transform.position.x; float y = gameObject.transform.position.y; if (x > 12 && y < 6 && y > -6){ GameObject.Find ("PalletHandler/East").GetComponent<Pallet>().AddCube(gameObject); GameObject.Find ("PalletHandler/EastText").GetComponent<HUD>().isValid = true; gameObject.transform.localScale *= .5f; disable (); } else if (x < -12 && y < 6 && y > -6){ GameObject.Find ("PalletHandler/West").GetComponent<Pallet>().AddCube(gameObject); GameObject.Find ("PalletHandler/WestText").GetComponent<HUD>().isValid = true; gameObject.transform.localScale *= .5f; disable (); } else if (y > 6 && x < 8 && x > -8){ GameObject.Find ("PalletHandler/North").GetComponent<Pallet>().AddCube(gameObject); GameObject.Find ("PalletHandler/NorthText").GetComponent<HUD>().isValid = true; gameObject.transform.localScale *= .5f; disable (); } else if (y < -6 && x < 8 && x > -8){ GameObject.Find ("PalletHandler/South").GetComponent<Pallet>().AddCube(gameObject); GameObject.Find ("PalletHandler/SouthText").GetComponent<HUD>().isValid = true; gameObject.transform.localScale *= .5f; disable (); } else { gameObject.transform.parent = origin.transform.parent; gameObject.transform.position = origin.transform.position; } Destroy (origin); } //building is currently being placed on the map, but not released yet if (state == BuildingState.Dragging) { Vector3 pos = blueprint.transform.position; var controller = GameObject.FindGameObjectWithTag (Tags.GameController); var clock = controller.GetComponent<Clock> (); if (blueprint.isColliding()){ Debug.Log ("blueprint.iscolliding = true"); switch(gameObject.name){ case "City": clock.spendMaterial(-(buildings.City)); break; case "Factory": clock.spendMaterial(-(buildings.Factory)); break; case "Farm": clock.spendMaterial(-(buildings.Farm)); break; case "Fishing": clock.spendMaterial(-(buildings.Fishing)); break; case "Lumber": clock.spendMaterial(-(buildings.Lumber)); break; case "Mine": clock.spendMaterial(-(buildings.Mine)); break; case "Power": clock.spendMaterial(-(buildings.Power)); break; case "School": clock.spendMaterial(-(buildings.School)); break; } Destroy (gameObject); Destroy (blueprint.gameObject); return; } else if(clock.getMaterial() < 0){ switch(gameObject.name){ case "City": clock.spendMaterial(-(buildings.City)); break; case "Factory": clock.spendMaterial(-(buildings.Factory)); break; case "Farm": clock.spendMaterial(-(buildings.Farm)); break; case "Fishing": clock.spendMaterial(-(buildings.Fishing)); break; case "Lumber": clock.spendMaterial(-(buildings.Lumber)); break; case "Mine": clock.spendMaterial(-(buildings.Mine)); break; case "Power": clock.spendMaterial(-(buildings.Power)); break; case "School": clock.spendMaterial(-(buildings.School)); break; } Destroy (gameObject); Destroy (blueprint.gameObject); return; } //can place building Destroy (blueprint.gameObject); GetComponent<PanGesture>().enabled = false; pos.x = RoundOff (pos.x); pos.y = RoundOff (pos.y); pos.z = 0.0f; gameObject.transform.position = pos; state = BuildingState.Built; gameObject.tag = Tags.Built; } }