/// <summary> /// /// called when this player captures a sector /// updates this players attack and defence bonuses /// sets the sectors owner and updates its colour /// /// </summary> /// <param name="sector">The sector that is being captured by this player</param> public void Capture(Sector sector) { // capture the given sector // store a copy of the sector's previous owner Player previousOwner = sector.GetOwner(); // add the sector to the list of owned sectors ownedSectors.Add(sector); // remove the sector from the previous owner's // list of sectors if (previousOwner != null) { previousOwner.ownedSectors.Remove(sector); } // set the sector's owner to this player sector.SetOwner(this); // if the sector contains a landmark if (sector.GetLandmark() != null) { Landmark landmark = sector.GetLandmark(); // remove the landmark's resource bonus from the previous // owner and add it to this player if (landmark.GetResourceType() == Landmark.ResourceType.Attack) { this.attack += landmark.GetAmount(); if (previousOwner != null) { previousOwner.attack -= landmark.GetAmount(); } } else if (landmark.GetResourceType() == Landmark.ResourceType.Defence) { this.defence += landmark.GetAmount(); if (previousOwner != null) { previousOwner.defence -= landmark.GetAmount(); } } } if (sector.IsVC()) { game.NextTurnState(); // update turn mode before game is saved sector.SetVC(false); // set VC to false so game can only be triggered once SavedGame.Save("_tmp", game); SceneManager.LoadScene(2); } }
public override void activatePunishment() { //This method is called when the card is activated. It first colours all enemy units green, then calculates the amount of PVC bonus //earnt by each player. The enemy player's bonuses are then reset. Map map = GetOwner().GetGame().gameMap.GetComponent <Map>(); //Colour the units. foreach (Sector sector in map.sectors) { Unit unit = sector.GetUnit(); if (unit != null && sector.GetOwner() != this.GetOwner()) { unit.SetColor(new Color(0.62f, 0.71f, 0.47f)); unit.gameObject.GetComponent <Renderer> ().material.color = unit.GetColor(); } } //Calculate the amount of PVC bonus each of the players own and add it to the playerPvcBonuses list. foreach (Player player in map.game.players) { if (player != this.GetOwner()) { int[] bonuses = new int[2]; bonuses [0] = player.GetBeer(); bonuses [1] = player.GetKnowledge(); foreach (Sector sector in player.ownedSectors) { Landmark landmark = sector.GetLandmark(); if (landmark != null) { if (landmark.GetResourceType() == Landmark.ResourceType.Beer) { bonuses [0] = bonuses [0] - landmark.GetAmount(); } else if (landmark.GetResourceType() == Landmark.ResourceType.Knowledge) { bonuses [1] = bonuses [1] - landmark.GetAmount(); } } } playerPvcBonuses [player] = bonuses; // Reset the players bonuses player.SetBeer(0); player.SetKnowledge(0); } } Debug.Log("Flu activated!"); }
public void Capture(Sector sector) { // capture the given sector // store a copy of the sector's previous owner Player previousOwner = sector.GetOwner(); // add the sector to the list of owned sectors ownedSectors.Add(sector); // remove the sector from the previous owner's // list of sectors if (previousOwner != null) { previousOwner.ownedSectors.Remove(sector); } // set the sector's owner to this player sector.SetOwner(this); // if the sector contains a landmark if (sector.GetLandmark() != null) { Landmark landmark = sector.GetLandmark(); // remove the landmark's resource bonus from the previous // owner and add it to this player if (landmark.GetResourceType() == Landmark.ResourceType.Beer) { this.beer += landmark.GetAmount(); if (previousOwner != null) { previousOwner.beer -= landmark.GetAmount(); } } else if (landmark.GetResourceType() == Landmark.ResourceType.Knowledge) { this.knowledge += landmark.GetAmount(); if (previousOwner != null) { previousOwner.knowledge -= landmark.GetAmount(); } } } }
public void Capture(Sector sector) // capture the given sector // store a copy of the sector's previous owner { Player previousOwner = sector.GetOwner(); // add the sector to the list of owned sectors ownedSectors.Add(sector); // remove the sector from the previous owner's // list of sectors if (previousOwner != null) { previousOwner.ownedSectors.Remove(sector); } // set the sector's owner to this player sector.SetOwner(this); // if the sector contains a landmark if (sector.GetLandmark() != null) { Landmark landmark = sector.GetLandmark(); // remove the landmark's resource bonus from the previous // owner and add it to this player if (landmark.GetResourceType() == Landmark.ResourceType.Beer) { this.beer += landmark.GetAmount(); if (previousOwner != null) { //ASSESSMENT4 ADDITION: avoid bonuses from becoming negative when FreshersFlu card is played. previousOwner.beer = Mathf.Max(previousOwner.beer - landmark.GetAmount(), 0); } } else if (landmark.GetResourceType() == Landmark.ResourceType.Knowledge) { this.knowledge += landmark.GetAmount(); if (previousOwner != null) { //ASSESSMENT4 ADDITION: avoid bonuses from becoming negative when FreshersFlu card is played. previousOwner.knowledge = Mathf.Max(previousOwner.knowledge - landmark.GetAmount(), 0); } } } }
public override void deactivatePunishment() { Map map = GetOwner().GetGame().gameMap.GetComponent <Map>(); //Deactivates the card's visual effect. foreach (Sector sector in map.sectors) { Unit unit = sector.GetUnit(); if (unit != null && sector.GetOwner() != this.GetOwner()) { unit.SetColor(Color.white); unit.gameObject.GetComponent <Renderer> ().material.color = unit.GetColor(); } } //Returns the bonuses back to normal by recalculating how much bonus they should have. foreach (Player player in playerPvcBonuses.Keys) { //Reset the player's bonuses => any PVC bonus gained when the card is active is lost. player.SetBeer(0); player.SetKnowledge(0); int[] bonuses = playerPvcBonuses [player]; foreach (Sector sector in player.ownedSectors) { Landmark landmark = sector.GetLandmark(); if (landmark != null) { if (landmark.GetResourceType() == Landmark.ResourceType.Beer) { bonuses [0] += landmark.GetAmount(); } else if (landmark.GetResourceType() == Landmark.ResourceType.Knowledge) { bonuses [1] += landmark.GetAmount(); } } } // Set the players bonuses back to normal. player.SetBeer(player.GetBeer() + bonuses[0]); player.SetKnowledge(player.GetKnowledge() + bonuses [1]); } this.SetOwner(null); }
public IEnumerator SpawnVice_AddsAViceChancellorLandmarkToASpecificSector() { Setup(); //Tests that calling spawnVice with a sectorID > -1 creates a ViceChancellor landmark in the sector associated with the sectorID. Sector aSector = map.sectors [3]; game.spawnVice(3); Landmark viceLandmark = aSector.GetLandmark(); Assert.NotNull(viceLandmark, "A landmark was not created in sector: " + aSector.name); Assert.AreEqual(Landmark.ResourceType.ViceChancellor, viceLandmark.GetResourceType()); yield return(null); }