Exemplo n.º 1
0
        /// <summary> Rebuild unit list. </summary>
        public void BuildUnitList()
        {
            if (Members == null)
            {
                Units = null;
                return;
            }

            Units = new ObservableCollection <string>();

            // Use UnitDetails if available, since it can contain units not found
            // in any player's roster.
            if (UnitDetails != null && UnitDetails.Count() > 0)
            {
                foreach (var name in UnitDetails.Where(u => u.combatType == goh_ui.UnitDetails.COMBATTYPE_CHARACTER).Select(u => u.name).OrderBy(x => x))
                {
                    Units.Add(name);
                }
                return;
            }

            // If UnitDetails not available, derive a list by combining the members' rosters.
            var units = Members.Select(m => m.Roster.Where(u => u.combatType == goh_ui.UnitDetails.COMBATTYPE_CHARACTER)
                                       .Select(c => c.name)) // map each member to an array of unit names
                        .SelectMany(x => x)                  // flatten list
                        .Distinct()                          // de-duplicate
                        .OrderBy(x => x);                    // sort alphabetically

            foreach (var unit in units)
            {
                Units.Add(unit);
            }
        }
Exemplo n.º 2
0
 public void Load(UnitDetails newDetails)
 {
     transform.position   = SaveManager.StringToVector(newDetails.position);
     transform.rotation   = SaveManager.StringToQuaternion(newDetails.rotation);
     transform.localScale = SaveManager.StringToVector(newDetails.localScale);
     unitDetails          = newDetails;
 }
Exemplo n.º 3
0
 public void AddUnitDetails(UnitDetails details)
 {
     if (UnitsAdded != null)
     {
         UnitsAdded(details);
     }
 }
Exemplo n.º 4
0
    public override void OnEnter()
    {
        Machine.Actor.GetComponent <UnitStateManager>().Active = true;

        unitDetails = Machine.Actor.GetComponent <UnitDetails>();
        unitTilemap = ObjectReferences.Instance.UnitTilemap;
    }
Exemplo n.º 5
0
    List <GameObject> FindUnitsInRange(int range, int originGridX, int originGridY)
    {
        List <GameObject>  units        = new List <GameObject>();
        List <TileDetails> tilesInRange = new List <TileDetails>();

        tilesInRange = GetTilesInRange(2, originGridX, originGridY);

        foreach (GameObject u in GameManager.Instance.AllUnits)
        {
            if (u == unitDetails.gameObject)
            {
                continue;
            }
            UnitDetails unitInfo = u.GetComponent <UnitDetails>();
            if (tilesInRange.Exists(x => IsUnitOnTile(unitInfo, x)) && unitInfo.TeamNumber != unitDetails.TeamNumber)
            {
                units.Add(u);
            }
            //if (unitInfo.CurrentGridX == originGridX - 1 && unitInfo.CurrentGridY == originGridY && unitInfo.TeamNumber != unitDetails.TeamNumber)
            //{
            //    units.Add(u);
            //}
            //if (unitInfo.CurrentGridX == originGridX && unitInfo.CurrentGridY == originGridY + 1 && unitInfo.TeamNumber != unitDetails.TeamNumber)
            //{
            //    units.Add(u);
            //}
            //if (unitInfo.CurrentGridX == originGridX && unitInfo.CurrentGridY == originGridY - 1 && unitInfo.TeamNumber != unitDetails.TeamNumber)
            //{
            //    units.Add(u);
            //}
        }
        return(units);
    }
Exemplo n.º 6
0
 public Looter(UnitDetails unitDetails)
     : base(unitDetails)
 {
     this.PlayerId = unitDetails.PlayerId;
     this.Mass     = unitDetails.Mass;
     this.Speed    = unitDetails.Speed;
 }
Exemplo n.º 7
0
    List <GameObject> FindAdjacentUnits(Node n)
    {
        List <GameObject> units = new List <GameObject>();
        int originGridX         = (int)n.Position.x;
        int originGridY         = (int)n.Position.y;

        foreach (GameObject u in GameManager.Instance.PlayerTeam.TeamUnits)
        {
            UnitDetails unitInfo = u.GetComponent <UnitDetails>();
            if (unitInfo.CurrentGridX == originGridX + 1 && unitInfo.CurrentGridY == originGridY && unitInfo.TeamNumber != unitDetails.TeamNumber)
            {
                units.Add(u);
            }
            if (unitInfo.CurrentGridX == originGridX - 1 && unitInfo.CurrentGridY == originGridY && unitInfo.TeamNumber != unitDetails.TeamNumber)
            {
                units.Add(u);
            }
            if (unitInfo.CurrentGridX == originGridX && unitInfo.CurrentGridY == originGridY + 1 && unitInfo.TeamNumber != unitDetails.TeamNumber)
            {
                units.Add(u);
            }
            if (unitInfo.CurrentGridX == originGridX && unitInfo.CurrentGridY == originGridY - 1 && unitInfo.TeamNumber != unitDetails.TeamNumber)
            {
                units.Add(u);
            }
        }
        return(units);
    }
Exemplo n.º 8
0
        /// <summary> Unit filtering logic. </summary>
        private void FilterUnits(object sender, FilterEventArgs e)
        {
            // If filters aren't supported, return everything
            if (UnitDetails == null || UnitDetails.Count() == 0)
            {
                e.Accepted = true;
                return;
            }

            // Look up character metadata
            var character = e.Item as string;
            var unit      = UnitDetails.Where(u => u.name == character).FirstOrDefault();

            if (unit == null)
            {
                e.Accepted = false;
                return;
            }

            // Apply selected filter
            switch (SelectedFilter)
            {
            // Handle generic filters
            case "All": e.Accepted = true; break;

            case "Light Side": e.Accepted = unit.forceAlignment == goh_ui.UnitDetails.ALIGNMENT_LIGHT; break;

            case "Dark Side": e.Accepted = unit.forceAlignment == goh_ui.UnitDetails.ALIGNMENT_DARK; break;

            // Handle tag-based filters
            default: e.Accepted = unit.categoryIdList.Contains(SelectedFilter); break;
            }
        }
Exemplo n.º 9
0
 bool IsUnitOnTile(UnitDetails unit, TileDetails tile)
 {
     if (tile != null)
     {
         return(unit.CurrentGridX == tile.GridPos.x && unit.CurrentGridY == tile.GridPos.y);
     }
     return(false);
 }
Exemplo n.º 10
0
    private void Awake()
    {
        if (UnitDetails.Instance && UnitDetails.Instance != this)
        {
            DestroyImmediate(this.gameObject);
            return;
        }

        UnitDetails.Instance = this;
    }
Exemplo n.º 11
0
    private void AddToList(UnitDetails details)
    {
        //Commander.Units.Add(details);

        GameObject button = Instantiate(UnitDetailPrefab, lstGridUnits);

        UnitControlPanel gridButton = button.GetComponent <UnitControlPanel>();

        gridButton.Initialize(details, unitCamSwitch);
        Debug.Log("Button created");
    }
Exemplo n.º 12
0
    private void TrainUnit()
    {
        Base.CreatedUnits++;

        GameObject  unit    = Instantiate(UnitPrefab, UnitSpawnLocation.position, Quaternion.identity);
        UnitDetails details = unit.GetComponent <UnitDetails>();

        details.SetDetails(Base.Owner, Base.CreatedUnits, 1f, 0.25f, 1f);
        Base.Owner.AddUnitDetails(details);

        IsTraining = false;
    }
Exemplo n.º 13
0
 public void SetSelectedUnit(Unit unit)
 {
     selectedUnit = unit;
     if (unit != null)
     {
         UnitDetails.Instance().ShowUnitDetails(unit);
     }
     else
     {
         UnitDetails.Instance().Hide();
     }
 }
Exemplo n.º 14
0
    // Update is called once per frame
    void Update()
    {
        if (GameManager.gameState == GameState.Battling)
        {
            CurrentRescource += (Time.deltaTime * RescourceGenerationRate);
            if (CurrentRescource >= RequiredRescource)
            {
                NewUnitPositon.x = parentPosition.position.x + Random.Range(-2f, 2.1f);
                NewUnitPositon.z = parentPosition.position.z + Random.Range(-2f, 2.1f);
                NewUnitPositon.y = 0;


                //Create new unit
                GameObject  go      = Instantiate(UnitPrefab, NewUnitPositon, Quaternion.identity);
                UnitDetails newUnit = go.GetComponent <UnitDetails>();
                //Set details of new unit
                //ID for enemy units only instanciated here, ID is managed internally
                newUnit.SetDetails(Base.Owner, id, 1f, 0.2f, 1f);
                id++;
                //Add to list
                unitsWaiting.Add(go.GetComponent <UnitComponent>());
                //Remove cost of unit
                CurrentRescource -= RequiredRescource;
            }

            if (unitsWaiting.Count >= 3)
            {
                //Assign random starting node
                SelectedRoute = staringNodes[Random.Range(0, 3)];
                //REMOVE BEFORE RELEASE
                //SelectedRoute = staringNodes[0];
                //Set starting node
                //unitsWaiting.ForEach(uw => uw.GetComponent<AIPathFollower>().CurrentNode = SelectedRoute);
                foreach (var uw in unitsWaiting)
                {
                    if (uw != null)
                    {
                        uw.GetComponent <AIPathFollower>().CurrentNode = SelectedRoute;
                    }
                    uw.GetComponent <AIPathFollower>().Invoke("MoveToPathNode", 1);
                }

                //Tell units to start moving
                //unitsWaiting.ForEach(uw => uw.GetComponent<AIPathFollower>().Invoke("MoveToPathNode", 1));
                //Clear waiting list
                unitsWaiting.Clear();
            }
        }
    }
Exemplo n.º 15
0
    private void OnTriggerExit(Collider collision)
    {
        //check reverse collision is with unittype
        UnitDetails removeUnit = collision.gameObject.GetComponent <UnitDetails>();

        if (removeUnit != null)
        {
            if (collision.gameObject.tag.Equals("Player"))
            {
                EnemiesToAttack.Remove(removeUnit);
                //if (AttackThese.Count == 0)//Check if enemies still in range
                //    CanSeeTarget = false;
            }
        }
    }
Exemplo n.º 16
0
        public static IOBalanceDBV3Entity.Units DtoToEntity(this UnitDetails dto)
        {
            IOBalanceDBV3Entity.Units entity = null;

            if (!dto.IsNull())
            {
                entity = new IOBalanceDBV3Entity.Units
                {
                    UnitID          = dto.UnitId,
                    UnitDescription = dto.UnitDescription
                };
            }

            return(entity);
        }
Exemplo n.º 17
0
    private void OnTriggerEnter(Collider collision)
    {
        UnitDetails newUnit = collision.gameObject.GetComponent <UnitDetails>();

        if (newUnit != null)
        {
            if (collision.gameObject.tag.Equals("Player"))
            {
                CanSeeTarget = true;
                EnemiesToAttack.Add(newUnit);
            }
        }
        else
        {
            CanSeeTarget = false;
        }
    }
Exemplo n.º 18
0
        /// <summary> Rebuild the list of available filters. </summary>
        private void BuildFilterList()
        {
            Filters.Clear();

            if (UnitDetails == null || UnitDetails.Count() == 0)
            {
                return;
            }

            // Add a few generic filters at the top of the list.
            Filters.Add("All");
            Filters.Add("Light Side");
            Filters.Add("Dark Side");

            // Add filters based on unit tags
            Filters.AddRange(UnitDetails.Select(u => u.categoryIdList).SelectMany(x => x).Distinct().OrderBy(x => x));
        }
    //Used to create units
    public void CreateUnit(string unitName)
    {
        //Check to see if we have a unit
        if (unitLookup.ContainsKey(unitName))
        {
            //Units to build
            UnitDetails unitToBuild = unitLookup[unitName];

            //Get a random spawn location in a circle
            Vector2 spawnLocationOffset = Random.insideUnitCircle * spawnRange;
            Vector3 spawnLocation       = spawnPoint.transform.position;
            spawnLocation.x += spawnLocationOffset.x;
            spawnLocation.z += spawnLocationOffset.y;

            //Spawn
            Instantiate <GameObject>(unitToBuild.prefab, spawnLocation, Quaternion.identity);
        }
    }
Exemplo n.º 20
0
    public void DealDamage(UnitDetails target)
    {
        int hit = Random.Range(0, 100);

        if (hit <= glanceChance)
        {
            target.Health -= glanceDamage;
            Debug.Log("A glancing blow...");
        }
        else if (hit >= 100 - criticalChance)
        {
            target.Health -= criticalDamage;
            Debug.Log("A critical hit!");
        }
        else
        {
            target.Health -= normalDamage;
        }
    }
Exemplo n.º 21
0
 void Attack()
 {
     AttackThis = EnemiesToAttack[0];
     if (Me != null && AttackThis != null)
     {
         //Me.AttackModifier = Me.SignModifier(AttackThis.myType) * Me.LevelModifier(AttackThis);
         if (Time.deltaTime <= AttackDelay)
         {
             AttackThis.Health -= Me.AttackPower * Me.AttackModifier;
             //Reset timer
             timer = 0f;
             Debug.Log(Me.ToString());
             //Debug.Log(AttackThis.ToString());
         }
     }
     if (AttackThis == null)
     {
         CanSeeTarget = false;
     }
 }
Exemplo n.º 22
0
    static void Main(string[] args)
    {
        while (true)
        {
            var gameContext = new GameContext();
            int myScore     = int.Parse(Console.ReadLine());
            gameContext.MyScore = myScore;
            int enemyScore1 = int.Parse(Console.ReadLine());
            gameContext.EnemyOneScore = enemyScore1;
            int enemyScore2 = int.Parse(Console.ReadLine());
            gameContext.EnemyTwoScore = enemyScore2;
            int myRage = int.Parse(Console.ReadLine());
            gameContext.MyRage = myRage;
            int enemyRage1 = int.Parse(Console.ReadLine());
            gameContext.EnemyOneRage = enemyRage1;
            int enemyRage2 = int.Parse(Console.ReadLine());
            gameContext.EnemyTwoRage = enemyRage2;
            int unitCount = int.Parse(Console.ReadLine());
            for (int i = 0; i < unitCount; i++)
            {
                string[] inputs = Console.ReadLine().Split(' ');

                var unitDetails = new UnitDetails()
                {
                    UnitId        = int.Parse(inputs[0]),
                    UnitType      = int.Parse(inputs[1]),
                    PlayerId      = int.Parse(inputs[2]),
                    Mass          = float.Parse(inputs[3]),
                    Radius        = int.Parse(inputs[4]),
                    Position      = new Position(int.Parse(inputs[5]), int.Parse(inputs[6])),
                    Speed         = new Speed(int.Parse(inputs[7]), int.Parse(inputs[8])),
                    Extra         = int.Parse(inputs[9]),
                    WaterCapacity = int.Parse(inputs[10])
                };

                gameContext.InitializeUnit(unitDetails);
            }

            gameContext.ProcessTurn();
        }
    }
Exemplo n.º 23
0
    void Update()
    {
        //Check if enemy is dead
        if (AttackThis != null && AttackThis.Health <= 0)
        {
            EnemiesToAttack.Remove(AttackThis);
            Destroy(AttackThis.gameObject);
        }
        if (AttackThis == null)             //When HP reaches 0, object is destroyed which may leave null
        {
            if (EnemiesToAttack.Count <= 0) //Check if units in range
            {
                return;
            }
            else //set target to be first element of Enemy list
            {
                AttackThis = EnemiesToAttack[0];
            }
        }

        if (EnemiesToAttack.Count > 0)
        {
            if (timer <= 0f)
            {
                timer = AttackDelay;
            }

            if (timer > 0f)
            {
                timer -= Time.deltaTime;
            }

            if (timer <= 0f && CanSeeTarget)
            {
                Attack();
            }
        }
    }
Exemplo n.º 24
0
 public void Initialize(UnitDetails details, UnitCameraSwitcher switcher)
 {
     Name.text   = details.Name;
     Type.text   = details.myType.ToString();
     unitDetails = details;
 }
Exemplo n.º 25
0
 public Doof(UnitDetails unitDetails)
     : base(unitDetails)
 {
     this.Friction = Constants.DoofFriction;
 }
Exemplo n.º 26
0
 public Destroyer(UnitDetails unitDetails)
     : base(unitDetails)
 {
     this.Friction = Constants.DestroyerFriction;
 }
Exemplo n.º 27
0
 public Reaper(UnitDetails unitDetails)
     : base(unitDetails)
 {
     this.Friction = Constants.ReaperFriction;
 }
Exemplo n.º 28
0
 public OilPool(UnitDetails unitDetails)
     : base(unitDetails)
 {
     this.RemainingDuration = unitDetails.Extra;
 }
Exemplo n.º 29
0
 public Wreck(UnitDetails unitDetails)
     : base(unitDetails)
 {
     this.WaterAmount = unitDetails.Extra;
 }
Exemplo n.º 30
0
 public Tanker(UnitDetails unitDetails)
     : base(unitDetails)
 {
     this.WaterAmount   = unitDetails.Extra;
     this.WaterCapacity = unitDetails.WaterCapacity;
 }