public async Task <ActionResult> DeleteConfirmed(int id) { MainBuilding mainBuilding = await db.MainBuildings.FindAsync(id); db.MainBuildings.Remove(mainBuilding); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public bool BuildUnit() { MainBuilding building = (MainBuilding)SenseOwnBuildings().Where(b => b is MainBuilding).FirstOrDefault(); if (building == null) { return(false); } return(BuildUnit(building)); }
public async Task <ActionResult> Edit([Bind(Include = "PrimaryKey,HarvestSpeed,Name,Level,MaxLevel,ImgUrl")] MainBuilding mainBuilding) { if (ModelState.IsValid) { db.Entry(mainBuilding).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(mainBuilding)); }
public async Task <ActionResult> Create([Bind(Include = "PrimaryKey,HarvestSpeed,Name,Level,MaxLevel,ImgUrl")] MainBuilding mainBuilding) { if (ModelState.IsValid) { db.MainBuildings.Add(mainBuilding); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(mainBuilding)); }
// GET: MainBuildings/Delete/5 public async Task <ActionResult> Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } MainBuilding mainBuilding = await db.MainBuildings.FindAsync(id); if (mainBuilding == null) { return(HttpNotFound()); } return(View(mainBuilding)); }
public virtual void Start() { _health.enabled = true; if (!photonView.IsMine) { return; } _enemyMainBuilding = FindEnemyMainBuilding(); if (_navMeshAgent != null) { _navMeshAgent.enabled = true; _navMeshAgent.isStopped = true; } }
/// <summary> /// Trigger for fighting something (building or another moving army) /// </summary> /// <param name="collision"></param> public void OnTriggerEnter2D(Collider2D collision) { GameObject other = collision.gameObject; //if it's a production building the building is hurt by the population of the army UnitBuildingLife unit = other.GetComponent <UnitBuildingLife>(); if (unit != null) { int life = unit.life; unit.HurtBuilding(this.army.TotalUnit); this.army.RemoveUnits(life); SoundManager.instance.RandomizeSfx(this.Boom2); } else { //if it's touching another moving army then we are resoluting the fight MovingArmy _army = other.GetComponent <MovingArmy>(); if (_army != null) { this.army.ConfrontArmy(_army.army); if (this.Boom1 != null && this.Boom2 != null) { SoundManager.instance.RandomizeSfx(this.Boom1); } _army.CheckDestroy(); } else { //if it's touching the main building then we fight the reserve army MainBuilding mainBuilding = other.GetComponent <MainBuilding>(); if (mainBuilding != null) { this.army.ConfrontArmy(mainBuilding.player.reserveArmy); mainBuilding.CheckDestoy(); } } } this.CheckDestroy(); }
public bool BuildUnit(MainBuilding building) => playerState.playerPurchases.Get(PurchasesEnum.Unit).Do(building);
// Start is called before the first frame update void Start() { resUI = GetComponent <ResUI>(); ui = GetComponent <UI>(); mainBuilding = GetComponent <MainBuilding>(); BarracksPanel = new GameObject(); WarriorButton = new GameObject(); WarriorText = new GameObject(); RangeUnitButton = new GameObject(); RangeUnitText = new GameObject(); ui.CreatePanel( BarracksPanel, "BarracksPanel", ui.myGO, ui.UIbackgroud, 0.5f, new Vector3(0f, 0f, 0f), new Vector2(0.30f, 0.30f), new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f), ui); ui.createButton(WarriorButton, BarracksPanel, "WarriorButton", new Vector3(0f, 0f, 0f), new Vector2(0.5f, 1f), new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f)); WarriorButton.GetComponent <Button>().onClick.AddListener(() => { mainBuilding.RecruitUnit(GetComponent <Prefabs>().ListOFUnits["Warrior"]); }); ui.createButton(RangeUnitButton, BarracksPanel, "RangeUnitButton", new Vector3(0f, 0f, 0f), new Vector2(1f, 1f), new Vector2(0.5f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f)); RangeUnitButton.GetComponent <Button>().onClick.AddListener(() => { mainBuilding.RecruitUnit(GetComponent <Prefabs>().ListOFUnits["RangeUnit"]); }); ui.CreateText(WarriorText, WarriorButton, "Warrior " + " 50W " + "100G", ui.ArialFont, new Vector2(1f, 1f), new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f) ); ui.CreateText(RangeUnitText, RangeUnitButton, "Range Unit " + " 100W " + "50G", ui.ArialFont, new Vector2(1f, 1f), new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 0f) ); }
// Use this for initialization void Start() { b = GameObject.Find("factory_3").GetComponent<MainBuilding>(); }
void Awake() { _cfg = FindObjectOfType <Config>(); _main = FindObjectOfType <MainBuilding>(); _moduleBag = new ShuffleBag <Module>(modulePrefabs); }
// Update is called once per frame void Update() { List <Transform> ownInteractable = gm.PlayerInteractable[ownUser.PlayerNum]; List <Transform> otherInteractable = gm.PlayerInteractable[otherUsers[0].PlayerNum]; List <MainBuilding> mainBuildings = new List <MainBuilding>(); List <FactoryBuilding> factoryBuildings = new List <FactoryBuilding>(); List <CollectorUnit> colUnits = new List <CollectorUnit>(); List <Unit> attackUnits = new List <Unit>(); List <Unit> otherUnits = new List <Unit>(); MainBuilding otherMain = null; FactoryBuilding otherfact = null; bool buildFactory = false; bool buildMain = false; foreach (Transform t in ownInteractable) { if (t.GetComponent <CollectorUnit>() != null) { if (t.GetComponent <CollectorUnit>().toBuild != null) { buildFactory = buildFactory || t.GetComponent <CollectorUnit>().toBuild.GetComponent <FactoryBuilding>() != null; buildMain = buildMain || t.GetComponent <CollectorUnit>().toBuild.GetComponent <MainBuilding>() != null; } colUnits.Add(t.GetComponent <CollectorUnit>()); } else if (t.GetComponent <Unit>() != null && t.GetComponent <Unit>().Type != Unit.UnitType.COLLECTOR_UNIT) { attackUnits.Add(t.GetComponent <Unit>()); } else if (t.GetComponent <MainBuilding>() != null) { mainBuildings.Add(t.GetComponent <MainBuilding>()); } else if (t.GetComponent <FactoryBuilding>() != null) { factoryBuildings.Add(t.GetComponent <FactoryBuilding>()); } } foreach (var t in otherInteractable) { if (t.GetComponent <MainBuilding>() != null) { otherMain = t.GetComponent <MainBuilding>(); } else if (t.GetComponent <Unit>() != null) { otherUnits.Add(t.GetComponent <Unit>()); } else if (t.GetComponent <FactoryBuilding>() != null) { otherfact = t.GetComponent <FactoryBuilding>(); } } if (mainBuildings.Count <= 0 && !buildMain && ownUser.Resources > 1000 && colUnits.Count > 0) { GameObject building = Instantiate(MainBuilding, ownUser.transform.position, colUnits[0].transform.rotation); building.GetComponent <Rigidbody>().constraints |= RigidbodyConstraints.FreezePositionY; building.GetComponent <Building>().setOwner(ownUser.PlayerNum); gm.RegisterInteractable(building.transform, ownUser.PlayerNum); colUnits[0].GetComponent <CollectorUnit>().StopBuild(); colUnits[0].GetComponent <Interactable>().setTarget(new WalkType(building.transform.position, WType.Build)); colUnits[0].GetComponent <CollectorUnit>().SetBuildBuilding(building); } if (mainBuildings.Count > 0 && colUnits.Count < MaxCollector && ownUser.Resources > 20) { int buildUnits = mainBuildings[0].getBO().Count; if (colUnits.Count + buildUnits < MaxCollector) { mainBuildings[0].addToList(Unit.UnitType.COLLECTOR_UNIT); } } if (mainBuildings.Count > 0 && !buildFactory && colUnits.Count > 0 && ownUser.Resources > 300 && factoryBuildings.Count <= 0) { GameObject building = Instantiate(FactoryBuilding, mainBuildings[0].transform.position + Vector3.right * 5 + Vector3.up * 3, colUnits[0].transform.rotation); building.GetComponent <Rigidbody>().constraints |= RigidbodyConstraints.FreezePositionY; building.GetComponent <Building>().setOwner(ownUser.PlayerNum); gm.RegisterInteractable(building.transform, ownUser.PlayerNum); colUnits[0].GetComponent <CollectorUnit>().StopBuild(); colUnits[0].GetComponent <Interactable>().setTarget(new WalkType(building.transform.position, WType.Build)); colUnits[0].GetComponent <CollectorUnit>().SetBuildBuilding(building); } if (factoryBuildings.Count > 0 && attackUnits.Count < MaxAttack) { int buildUnits = factoryBuildings[0].getBO().Count; if (attackUnits.Count + buildUnits < MaxAttack) { factoryBuildings[0].setTarget(new WalkType(factoryBuildings[0].transform.position + Vector3.right * 3 + Vector3.forward * 5)); factoryBuildings[0].addToList((Unit.UnitType)Random.Range(1, 3)); } } foreach (CollectorUnit cu in colUnits) { if (cu.target == null) { Transform selectedResource = null; float minDist = float.MaxValue; foreach (var r in gm.Resources) { float tempdist = 0; if ((tempdist = Vector3.Distance(r.position, cu.transform.position)) < minDist) { minDist = tempdist; selectedResource = r; } } if (selectedResource != null) { cu.setTarget(new WalkType(selectedResource.position, WType.Collect)); } } } if (otherUnits.Count > 0 && attackUnits.Count > 0) { attackUnits.ForEach(v => { if (v.target == null) { v.setTarget(new WalkType(otherUnits[Random.Range(0, otherUnits.Count)].transform)); } }); } if (otherfact != null && attackUnits.Count > 0) { attackUnits.ForEach(v => { if (v.target == null) { v.setTarget(new WalkType(otherfact.transform)); } }); } if (otherMain != null && attackUnits.Count > 0) { attackUnits.ForEach(v => { if (v.target == null) { v.setTarget(new WalkType(otherMain.transform)); } }); } }