Beispiel #1
0
    // Start is called before the first frame update
    void Start()
    {
        _gameData = GameObject.Find("Game_Data").GetComponent <GameData>();

        player = GameObject.Find("Player_1").GetComponent <Player>();

        playerSelectedCreature = player.getCurrentlySelectedCreature();

        _attackPatterns = _gameData.GetComponent <AttackPatterns>();
    }
Beispiel #2
0
    //Initialize fields
    void Start()
    {
        attackPatterns = new AttackPatterns();
        health         = new Health(startHealth);

        gun    = this.transform.Find("Gun").transform.gameObject;
        bullet = GameObject.FindGameObjectWithTag("Load").GetComponent <LoadList>().projectiles[0];

        randomState = 0;
    }
Beispiel #3
0
    IEnumerator OpenAttack(AttackPatterns a, int i)
    {
        int   index = i;
        float delay = a.attacks[index].delay;

        states.attack1 = a.attacks[index].attack1;
        states.attack2 = a.attacks[index].attack2;
        yield return(new WaitForSeconds(delay));

        states.attack1 = false;
        states.attack2 = false;

        if (index < a.attacks.Length - 1)
        {
            index++;
            StartCoroutine(OpenAttack(a, index));
        }
    }
Beispiel #4
0
    IEnumerator OpenAttack(AttackPatterns a, int i)
    {
        // ienumerator which counts delay and attack given to output attack type for AI as well as combo counter and hen they can attack
        int   index = i;
        float delay = a.attacks[index].delay;

        states.attack1 = a.attacks[index].attack1;
        states.attack2 = a.attacks[index].attack2;
        yield return(new WaitForSeconds(delay));

        states.attack1 = false;
        states.attack2 = false;

        if (index < a.attacks.Length - 1)
        {
            index++;
            StartCoroutine(OpenAttack(a, index));
        }
    }
Beispiel #5
0
    void FindAndLoadResources()
    {
        _board = GameObject.Find("Board").GetComponent <Board>();

        // get the size of each space from the Board component
        if (_board != null)
        {
            _spaceSize = _board.getSpaceSize();
        }

        _player = GameObject.Find("Player_" + _playerOwner).GetComponent <Player>();

        // get the size of each space from the Board component
        if (_player == null)
        {
            Debug.LogError("Player is null ::Creature.cs::Start()");
        }

        _gameData = GameObject.Find("Game_Data").GetComponent <GameData>();

        if (_gameData == null)
        {
            Debug.LogError("Game Data object is NULL");
        }

        _movementPatterns = _gameData.GetComponent <MovementPatterns>();

        if (_movementPatterns == null)
        {
            Debug.LogError("Movement Patterns script is NULL and should be on Game Data object");
        }

        _attackPatterns = _gameData.GetComponent <AttackPatterns>();

        if (_attackPatterns == null)
        {
            Debug.LogError("Attack Patterns script is NULL and should be on Game Data object");
        }
    }
Beispiel #6
0
//private stuff
    private void Awake()
    {
        //variable initalization
        patrolDirection = true;
        playerSpotted   = false;
        isDead          = false;
        health          = 1;
        player          = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerControl>();
        //taskManager = new TaskManager.TaskState();

        //class and component initialization
        attackPatterns = new AttackPatterns();
        taskList       = new TaskList();
        enemyVision    = new EnemyVision(this);
        pathFinder     = GetComponent <AIPath>();

        //initialize state machines
        mainFSM   = new StateMachine(this);
        attackFSM = new StateMachine(this);

        myAwake(); //called from derived class
    }
Beispiel #7
0
        private IEnumerator AttackPatternLoop(AttackPatternType pattern, float timeBeforeStarting)
        {
            yield return(new WaitForSeconds(timeBeforeStarting));

            while (true)
            {
                int        currentStep = _currentSteps[pattern];
                AttackStep attackStep  = AttackPatterns.GetNextAttackStep(pattern, currentStep);
                foreach (ProjectileAttack attack in attackStep.ProjectileAttacks)
                {
                    GameObject       prefab           = _prefabs[attack.Type];
                    Vector2          trajectory       = attack.Trajectory.magnitude == 0f ? GetTrajectoryTowardsPlayer() : attack.Trajectory;
                    GameObject       projectile       = Instantiate(prefab, _transform.position, LookRotation2D(trajectory), _bulletContainer);
                    ProjectileScript projectileScript = projectile.GetComponent <ProjectileScript>();

                    projectileScript.Initialize(playSpawnSound: attack.PlayAudio);
                }

                _currentSteps[pattern]++;
                yield return(new WaitForSeconds(attackStep.StepDelay));
            }
            // ReSharper disable once IteratorNeverReturns
        }
    // Use this for initialization
    void Awake()
    {
        lastMove.y = -1;
        isSpotted  = false;

        myRigidbody   = GetComponent <Rigidbody2D>();
        anim          = GetComponent <Animator>();
        myAudioSource = GetComponent <AudioSource>();
        myRenderer    = GetComponent <Renderer>();

        attackPatterns = new AttackPatterns();

        equip          = 0;
        capturedBullet = false;
        gun            = transform.Find("Gun").gameObject;

        playerLight = transform.Find("Player Light").gameObject.GetComponent <Light>();
        sceneLight  = GameObject.Find("Scene Light").gameObject.GetComponent <Light>();

        currStamina  = maxStamina;
        currTimeFuel = maxTimeFeul;

        moveSpeed = defaultSpeed;
    }
Beispiel #9
0
    protected override void OnUpdate()
    {
        var  attacker = GetEntityQuery(typeof(UnitAttack), typeof(Attack), typeof(Team), typeof(BoardPosition), typeof(UnitType));
        var  units    = GetEntityQuery(unitQuery);
        bool didHit   = false;

        if (attacker.CalculateLength() == 1)
        {
            var attackerEntity = attacker.ToEntityArray(Allocator.TempJob);
            units.SetFilter(new Team()
            {
                value = EntityManager.GetSharedComponentData <Team>(attackerEntity[0]).value * -1
            });
            var   target         = units.ToEntityArray(Allocator.TempJob);
            var   targetHP       = units.ToComponentDataArray <HP>(Allocator.TempJob);
            var   targetId       = units.ToComponentDataArray <Id>(Allocator.TempJob);
            var   targetPosition = units.ToComponentDataArray <BoardPosition>(Allocator.TempJob);
            var   targetType     = units.ToComponentDataArray <UnitType>(Allocator.TempJob);
            var   attackType     = attacker.ToComponentDataArray <Attack>(Allocator.TempJob);
            var   attackerPos    = attacker.ToComponentDataArray <BoardPosition>(Allocator.TempJob);
            float shift          = -1;
            List <SquadsManagement.attackData> attacks = new List <SquadsManagement.attackData>();
            int damage = 0;
            if (EntityManager.HasComponent <ExperiencedFighter>(attackerEntity[0]))
            {
                damage = DiceSystem.RollBunchOfDice(attackType[0].amountOfCubes, attackType[0].typeOfCubes, true);
            }
            else
            {
                damage = DiceSystem.RollBunchOfDice(attackType[0].amountOfCubes, attackType[0].typeOfCubes);
            }
            for (int i = 0; i < units.CalculateLength(); i++)
            {
                /*ATTACK DAMAGE DEAL*/
                if (AttackPatterns.chooseType(attackType[0].index, attackerPos[0].cell, targetPosition[i].cell) || (EntityManager.HasComponent <PizarroStrike>(attackerEntity[0]) && EntityManager.HasComponent <Curse>(target[0])))
                {
                    didHit = true;
                    PostUpdateCommands.AddComponent(target[i], new Target()
                    {
                    });
                    /*close-up targets creation*/
                    float delta = 0 + 1.5f * (shift + 1) * (shift % 2 == 0 ? 1 : -1);
                    var   e     = PostUpdateCommands.CreateEntity(closeUpTarget);
                    PostUpdateCommands.SetComponent(e, new View()
                    {
                        state = 2 /*damage*/, frame = 0
                    });
                    PostUpdateCommands.SetComponent(e, new UnitType()
                    {
                        index = targetType[i].index
                    });
                    PostUpdateCommands.SetComponent(e, new Translation()
                    {
                        Value = new float3(1030f + -100 * Mathf.Abs(delta), 180 + delta * 100, (4 + delta) * 0.1f)
                    });

                    shift += 0.6f;
                    if (EntityManager.HasComponent <Evasion>(target[i]))
                    {
                        damage = AttackPatterns.Evasion(damage);
                    }
                    if (EntityManager.HasComponent <Bleeding>(target[i]))
                    {
                        damage = EntityManager.GetComponentData <Bleeding>(target[i]).damage;
                    }
                    if (EntityManager.HasComponent <BrokenArmour>(target[i]) || EntityManager.HasComponent <DestroyedArmour>(target[i]))
                    {
                        damage *= 2;
                    }

                    string effect = AttackPatterns.chooseEffect(out damage, attackType[0].effect, EntityManager, PostUpdateCommands, attackerEntity[0], target[i], damage);
                    PostUpdateCommands.SetComponent <HP>(target[i], new HP()
                    {
                        currentValue = targetHP[i].currentValue - damage, startValue = targetHP[i].startValue
                    });
                    SquadsManagement.instance.allCards[targetId[i].value].GetComponent <UnitCardFight>().UpdateData(target[i], damage);


                    attacks.Add(new SquadsManagement.attackData()
                    {
                        targetId = targetId[i].value,
                        damage   = damage,
                        target   = target[i],
                        position = new float3(1030f + -100 * Mathf.Abs(delta), 180 + delta * 100, (4 + delta) * 0.1f)
                    });
                }
                SquadsManagement.instance.Attacks = attacks;
            }
            if (didHit == true)
            {
                /*close-up view creation*/
                var e = PostUpdateCommands.CreateEntity(closeUpAttack);
                PostUpdateCommands.SetComponent(e, new Translation()
                {
                    Value = new float3(1480, 180f, 1f)
                });
                PostUpdateCommands.SetComponent(e, new View()
                {
                    state = 1                                            /*attack*/
                });
                PostUpdateCommands.SetComponent(e, new UnitType()
                {
                    index = EntityManager.GetComponentData <UnitType>(attackerEntity[0]).index
                });
                PostUpdateCommands.AddComponent(attackerEntity[0], new UnitAnimation()
                {
                });
            }
            else
            {
                Translation pos = EntityManager.GetComponentData <Translation>(attackerEntity[0]);
                animationManager.instance.DestroyMassAnimationInstance(new animationManager.particleAnimation()
                {
                    name = "UnitCircle", position = new Vector3(pos.Value.x, pos.Value.y, -30)
                });
                animationManager.instance.CreateMassAnimationName(new animationManager.particleAnimation()
                {
                    name = "UnitCircle", position = new Vector3(pos.Value.x, pos.Value.y, -30)
                }, EntityManager.GetSharedComponentData <Team>(attackerEntity[0]).value);
            }
            PostUpdateCommands.RemoveComponent <UnitAttack>(attackerEntity[0]);
            target.Dispose();
            attackerEntity.Dispose();
            targetHP.Dispose();
            targetId.Dispose();
            targetPosition.Dispose();
            targetType.Dispose();
            attackType.Dispose();
            attackerPos.Dispose();
        }
    }
Beispiel #10
0
    protected override void OnUpdate()
    {
        availableCellsQueue = GetEntityQuery(typeof(AvailableCell), typeof(Cell));
        actionQueue         = GetEntityQuery(typeof(Action), typeof(Attack), typeof(Team), typeof(BoardPosition));
        unitsQueue          = GetEntityQuery(unitQuery);
        int bestValue    = 0;
        int bestCell     = 0;
        int bestDistance = int.MaxValue;

        if (actionQueue.CalculateLength() == 1 && availableCellsQueue.CalculateLength() > 0)
        {
            var attacker = actionQueue.ToEntityArray(Allocator.TempJob);
            unitsQueue.SetFilter(new Team()
            {
                value = EntityManager.GetSharedComponentData <Team>(attacker[0]).value * -1
            });
            var availableCells        = availableCellsQueue.ToEntityArray(Allocator.TempJob);
            var availableCellsNumbers = availableCellsQueue.ToComponentDataArray <Cell>(Allocator.TempJob);
            var attackType            = actionQueue.ToComponentDataArray <Attack>(Allocator.TempJob);
            var attackerPosition      = actionQueue.ToComponentDataArray <BoardPosition>(Allocator.TempJob);
            var targetPosition        = unitsQueue.ToComponentDataArray <BoardPosition>(Allocator.TempJob);
            var targetCost            = unitsQueue.ToComponentDataArray <Cost>(Allocator.TempJob);
            for (int i = 0; i < availableCells.Length; i++)
            {
                int value    = 0;
                int distance = int.MaxValue;
                for (int j = 0; j < unitsQueue.CalculateLength(); j++)
                {
                    if (AttackPatterns.chooseType(attackType[0].index, availableCellsNumbers[i].number, targetPosition[j].cell))
                    {
                        value += targetCost[j].value;
                    }
                    if (Mathf.Abs(availableCellsNumbers[i].number - targetPosition[j].cell) < distance)
                    {
                        distance = (availableCellsNumbers[i].number % 8 - targetPosition[j].cell % 8) * (availableCellsNumbers[i].number % 8 - targetPosition[j].cell % 8) + (availableCellsNumbers[i].number / 8 - targetPosition[j].cell / 8) * (availableCellsNumbers[i].number / 8 - targetPosition[j].cell / 8);
                    }
                }
                if (value == 0 && bestValue == 0)
                {
                    if (bestDistance > distance)
                    {
                        bestDistance = distance;
                        bestCell     = i;
                    }
                }
                else
                {
                    if (value >= bestValue)
                    {
                        bestValue = value;
                        bestCell  = i;
                    }
                }
            }
            PostUpdateCommands.AddComponent <Chosen>(availableCells[bestCell], new Chosen()
            {
            });
            PostUpdateCommands.SetComponent <BoardPosition>(attacker[0], new BoardPosition()
            {
                cell = availableCellsNumbers[bestCell].number
            });
            attacker.Dispose();
            attackerPosition.Dispose();
            availableCells.Dispose();
            availableCellsNumbers.Dispose();
            attackType.Dispose();
            targetCost.Dispose();
            targetPosition.Dispose();
        }
    }