Esempio n. 1
0
    public bool Combat(Player player)
    {
        velocity.X = Irbis.Irbis.Lerp(velocity.X, 0, movementLerpBuildup * Irbis.Irbis.DeltaTime);
        jumpTime   = 0;

        if (attackCooldownTimer <= 0)
        {
            attackID            = attackIDtracker++;
            attackCooldownTimer = attackCooldown;
            attacking           = Attacking.Attack1;
        }

        if (attacking != Attacking.No)
        {
            Hitbox();
            if (attackCollider.Intersects(player.Collider))
            {
                player.Hurt(attackDamage, true, Irbis.Irbis.Directions(collider.Center, Irbis.Irbis.jamie.Collider.Center));
            }
        }
        else
        {
            attackCollider = Rectangle.Empty;
            attackDamage   = 0f;
            attackID       = 0;
        }
        return(true);
    }
Esempio n. 2
0
        public static void AddComponents(EntityFactory factory)
        {
            // Apply these one after the other.
            // This will only initialize the inject variables of the behavior / component.
            // So, apply will be autogenerated for the different behaviors based on their injects.
            // Or do it even smarter?
            // So, since I'd like to make components structs in the future and store them somewhere
            // central (optionally), these can actually reference a global storage for them.

            // So this just adds the behavior
            Acting.AddTo(factory, null, Algos.SimpleAlgo, Order.Player);
            Moving.AddTo(factory);
            Digging.AddTo(factory);
            Pushable.AddTo(factory);
            Attacking.AddTo(factory, Attacking.GetTargetProviderFromInventory, Layers.REAL, Faction.Enemy | Faction.Environment);
            Attackable.AddTo(factory, Attackness.ALWAYS);
            Damageable.AddTo(factory, new Health(5));
            Displaceable.AddTo(factory, Layers.BLOCK);
            Ticking.AddTo(factory);

            FactionComponent.AddTo(factory, Faction.Player);
            Transform.AddTo(factory, Layers.REAL, TransformFlags.Default);
            Inventory.AddTo(factory);
            Inventory.AddInitTo(factory);

            // TODO: pass this an action
            Controllable.AddTo(factory,
                               // The default action is the AttackDigMove action.
                               Action.Compose(Attacking.Action, Digging.Action, Moving.Action));

            // TODO: rename the namespaces
            Stats.AddTo(factory, Registry.Global.Stats._map);
        }
Esempio n. 3
0
 // Use this for initialization
 void Start()
 {
     cc   = GetComponent <CharacterController2D>();
     rb   = GetComponent <Rigidbody2D>();
     anim = GetComponent <Animator>();
     atk  = GetComponent <Attacking>();
 }
Esempio n. 4
0
    // Start is called before the first frame update


    // Start is called before the first frame update
    void Start()
    {
        render  = gameObject.GetComponentInParent <Renderer>();
        rb      = gameObject.GetComponentInParent <Rigidbody>();
        getmove = gameObject.GetComponent <NEWS_MOVE>();
        getat   = GameObject.FindGameObjectWithTag("Player").GetComponent <Attacking>();
    }
Esempio n. 5
0
    void Awake()
    {
        _moving    = this.GetComponent <Moving>();
        _attacking = this.GetComponent <Attacking>();

        _player = GameObject.Find("Player");
    }
Esempio n. 6
0
        /// <summary>
        ///     Resets attacking phase recoloring everything back.
        ///     Notice: deploying phase passed in parameter must be corect in order
        ///     to make this method work properly.
        /// </summary>
        /// <param name="attackingPhase">Attacking phase</param>
        /// <param name="deployingPhase">Deploying phase</param>
        public void ResetAttackingPhase(Attacking attackingPhase, Deploying deployingPhase)
        {
            // TODO: check + should not clear
            var attacks = attackingPhase.Attacks;
            IEnumerable <IGrouping <Region, Attack> > attackerRegionsGroups = from attack in attacks
                                                                              group attack by attack.Attacker;
            var regionAttackingArmyPairEnumerable = from gr in attackerRegionsGroups
                                                    select new
            {
                Attacker      = gr.Key,
                AttackingArmy = gr.Sum(x => x.AttackingArmy)
            };

            foreach (var item in regionAttackingArmyPairEnumerable)
            {
                Region attacker = item.Attacker;

                IEnumerable <int> regionDeployedArmy = from tuple in deployingPhase.ArmiesDeployed
                                                       where tuple.Region == attacker
                                                       select tuple.Army;
                if (!regionDeployedArmy.Any())
                {
                    textDrawingHandler.OverDrawArmyNumber(attacker, attacker.Army);
                }
                else
                {
                    int army = regionDeployedArmy.First();
                    textDrawingHandler.OverDrawArmyNumber(attacker, army);
                }

                OnImageChanged?.Invoke();
            }
        }
    eAttackResult CalcAttackResult(Attacking damager)
    {
        if (currentAttackDirection == eAttackDirection.NoAttack)
        {
            // Not attacking at all, so no chance for defence.
            return(eAttackResult.Hit);
        }
        else if (currentAttackDirection == damager.currentAttackDirection)
        {
            // Matching attack directions, we have a chance for defence or
            // being vulnerable.
            switch (currentAttackWindow)
            {
            case eAttackWindow.Starting:
                return(eAttackResult.Parry);

            case eAttackWindow.Swinging:
            case eAttackWindow.Landing:
                return(eAttackResult.Block);

            case eAttackWindow.Landed:
            case eAttackWindow.Done:
                return(eAttackResult.Hit);
            }

            Dbg.Assert(false, "Unhandled enum case: " + currentAttackWindow);
            return(eAttackResult.Hit);
        }
        else
        {
            return(eAttackResult.Hit);
        }
    }
Esempio n. 8
0
 public static Attacking Instance()
 {
     if (instance == null)
     {
         instance = new Attacking();
     }
     return(instance);
 }
    private void Start()
    {
        _attacking         = GetComponent <Attacking>();
        _defaultAttackRate = _attacking._damage;
        Buffs.onFireRateChanged.AddListener(OnBuffModified);

        OnBuffModified();
    }
Esempio n. 10
0
    private void OnTriggerEnter2D(Collider2D collider)
    {
        Attacking attacking = collider.gameObject.GetComponent <Attacking>();

        if (attacking)
        {
            animator.SetTrigger("underAttackTrigger");
        }
    }
Esempio n. 11
0
    void Start()
    {
        //"Jump"
        attackMap["RightAttack"] = Attacking.eAttackDirection.Right;
        attackMap["LeftAttack"]  = Attacking.eAttackDirection.Left;
        attackMap["BackAttack"]  = Attacking.eAttackDirection.Back;

        attackController = GetComponentInChildren <Attacking>();
    }
Esempio n. 12
0
    private Attacking()
    {
        if (_instance != null)
        {
            return;
        }

        _instance = this;
    }
Esempio n. 13
0
    /**
     *   this is the updated fucntion for the state
     */
    public override void Excute(GameObject CallingObject)
    {
        Team TeamScript = CallingObject.GetComponent <Team>();

        if (TeamScript.InControl())
        {
            TeamScript.ChangeState(CallingObject, Attacking.Instance());
        }
    }
Esempio n. 14
0
    private void OnCollisionEnter2D(Collision2D collision)
    {
        Attacking script = collision.transform.GetComponent <Attacking>();

        if (script != null)
        {
            script.GetAttacked();
        }
    }
Esempio n. 15
0
 private void Attack()
 {
     //Begin attacking
     if (_canAttack == true)
     {
         Attacking?.Invoke();
         _canAttack = false;
     }
 }
 // Start is called before the first frame update
 void Start()
 {
     rb         = gameObject.GetComponent <Rigidbody>();
     render     = gameObject.GetComponent <Renderer>();
     anim       = gameObject.GetComponentInChildren <Animator>();
     player     = GameObject.FindGameObjectWithTag("Player");
     NavMesh    = GetComponent <NavMeshAgent>();
     controller = GetComponent <enemyController>();
     getat      = GameObject.FindGameObjectWithTag("Player").GetComponent <Attacking>();
 }
Esempio n. 17
0
        /// <summary>
        ///     Resets round, recoloring everything to previous color, writing
        ///     original numbers of armies.
        /// </summary>
        /// <param name="gameRound">Round to reset</param>
        internal void ResetRound(GameTurn gameRound)
        {
            Attacking attackingPhase = gameRound.Attacking;

            ResetAttackingPhase(attackingPhase, gameRound.Deploying);

            Deploying deployingPhase = gameRound.Deploying;

            ResetDeployingPhase(deployingPhase);
        }
Esempio n. 18
0
 public bool Enemy_OnPlayerAttack(Rectangle AttackCollider, Attacking Attack, Vector2 Damage)
 {
     if (AttackCollider.Intersects(collider))
     {
         float tempDamage = Irbis.Irbis.RandomFloatInRange(Damage);
         PlayerAttackCollision(tempDamage);
         Irbis.Irbis.WriteLine(name + " hit. health remaining:" + health + " (" + tempDamage + ")");
     }
     return(true);
 }
Esempio n. 19
0
    private void Start()
    {
        #region Configuring State Machine

        _animator       = GetComponent <Animator>();
        _spriteRenderer = GetComponent <SpriteRenderer>();
        _rb             = GetComponent <Rigidbody2D>();
        _collider       = GetComponent <Collider2D>();

        _stateMachine = new StateMachine();

        // Instantiating states
        var moving       = new Moving(this, _animator);
        var idle         = new Idle(this, _animator);
        var dashing      = new Dashing(this, _animator, _rb, _collider);
        var attacking    = new Attacking(this, _animator, _rb);
        var boomeranging = new Boomeranging(this, _animator, _rb);
        var swapping     = new Swapping(this, _animator, _rb);

        // Assigning transitions
        At(moving, idle, IsIdle());
        At(idle, moving, IsMoving());

        // Dashing
        At(idle, dashing, IsDashing());
        At(moving, dashing, IsDashing());
        At(dashing, idle, IsNotDashing());

        // Attacking
        At(idle, attacking, IsAttacking());
        At(moving, attacking, IsAttacking());
        At(attacking, idle, IsNotAttacking());

        // Boomeranging
        At(idle, boomeranging, IsBoomeranging());
        At(moving, boomeranging, IsBoomeranging());
        At(boomeranging, idle, IsNotBoomeranging());

        // Swapping
        _stateMachine.AddAnyTransition(swapping, IsSwapping());
        At(swapping, idle, IsNotSwapping());

        // Starting state
        _stateMachine.SetState(moving);

        // Method to assign transitions easily
        void At(IState to, IState from, Func <bool> condition) => _stateMachine.AddTransition(to, from, condition);

        #endregion

        #region Instantiating instance variables
        // Base sorting layer
        baseLayer = GetComponent <SpriteRenderer>().sortingOrder;
        #endregion
    }
Esempio n. 20
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        Attacking attacking = collider.gameObject.GetComponent <Attacking>();
        Health    health    = collider.gameObject.GetComponent <Health>();

        if (attacking && health)
        {
            health.DealDamage(damage);
            Destroy(gameObject);
        }
    }
Esempio n. 21
0
    // Start is called before the first frame update
    void Start()
    {
        currHealth = maxHealth;

        rb   = GetComponent <Rigidbody2D>();
        anim = GetComponent <Animator>();

        ps   = GetComponent <PlayerSpotting>();
        foll = GetComponent <Following>();
        att  = GetComponent <Attacking>();
    }
Esempio n. 22
0
    void Awake()
    {
        // Get references
        rb   = GetComponent <Rigidbody>();
        anim = GetComponent <Animator>();

        // Instantiate states
        idleState      = new IdleState(gameObject);
        walkingState   = new Walking(gameObject);
        attackingState = new Attacking(gameObject);
    }
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(this.gameObject);
     }
     DontDestroyOnLoad(this.gameObject);
 }
Esempio n. 24
0
 public bool Enemy_OnPlayerAttack(Rectangle AttackCollider, Attacking Attack, Vector2 Damage)
 {
     if (Irbis.Irbis.DistanceSquared(AttackCollider, position) <= radiusSquared)
     {
         Irbis.Irbis.WriteLine("hit fireball");
         damage                    = 0;
         radiusSquared             = -1;
         particleSystem.timeToLive = -1;
         dottiboy.timeToLive       = -1;
     }
     return(true);
 }
    // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
    //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    //{
    //
    //}

    // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
    override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        float absDistX = PlayerSpotting.playerRef ? Mathf.Abs(animator.gameObject.transform.position.x - PlayerSpotting.playerRef.transform.position.x) : 100f;
        float absDistY = PlayerSpotting.playerRef ? Mathf.Abs(animator.gameObject.transform.position.y - PlayerSpotting.playerRef.transform.position.y): 100f;

        if (absDistX <= Following.minDistBeforeAttacking && absDistY <= Following.minDistBeforeAttacking && !animator.GetBool("IsStunned"))
        {
            PlayerSpotting.playerRef.GetComponent <Health>().TakeDamage(damageOutput);
        }

        att         = animator.GetComponent <Attacking>();
        att.enabled = true;
    }
Esempio n. 26
0
    bool isTimeToSpawn(GameObject attackerGameObject)
    {
        Attacking attacker        = attackerGameObject.GetComponent <Attacking>();
        float     meanSpawnDelay  = attacker.seenEverySeconds;
        float     spawnsPerSecond = 1 / meanSpawnDelay;

        if (Time.deltaTime > meanSpawnDelay)
        {
        }
        float threshold = spawnsPerSecond * Time.deltaTime / 4;

        return(Random.value < threshold);
    }
Esempio n. 27
0
    // Start is called before the first frame update
    void Start()
    {
        PLAYER    = GameObject.FindGameObjectWithTag("Player");
        getattack = GameObject.FindGameObjectWithTag("Player").GetComponent <Attacking>();
        NavMesh   = GetComponent <NavMeshAgent>();
        Rb        = GetComponent <Rigidbody>();

        // Rb.velocity = Vector3.zero;
        NavMesh.isStopped = true;
        NavMesh.speed     = 8;
        NavMesh.SetDestination(RandoPos());
        //anim = GetComponent<Animator>();
        getcom = GameObject.FindGameObjectWithTag("S").GetComponent <Combat_Slime>();
    }
Esempio n. 28
0
        public static void Main()
        {
            Hopper.Core.Main.Init();
            Hopper.TestContent.Main.Init();

            attackerFactory = new EntityFactory();
            Transform.AddTo(attackerFactory, Layers.REAL, 0);
            Stats.AddTo(attackerFactory, Registry.Global.Stats._map);
            Attacking.AddTo(attackerFactory, entity => BufferedAttackTargetProvider.Simple, Layers.REAL, Faction.Any).SkipEmptyAttackPreset();
            World.Global = new World(3, 3);
            var attacker = World.Global.SpawnEntity(attackerFactory, new IntVector2(0, 0));

            attacker.Attack(IntVector2.Right);
        }
    void LandAttack()
    {
        GameObject attack_target = DetermineAttackTarget(currentAttackDirection);

        if (attack_target == null)
        {
            return;
        }

        Attacking     damagee = attack_target.GetComponentInChildren <Attacking>();
        eAttackResult result  = damagee.CalcAttackResult(this);

        damagee.HandleAttack(result);
    }
Esempio n. 30
0
        public AttackingTests()
        {
            InitScript.Init();

            // attacking requires stats and transform
            attackerFactory = new EntityFactory();
            Transform.AddTo(attackerFactory, Layers.REAL, 0);
            Stats.AddTo(attackerFactory, Registry.Global.Stats._map);
            Attacking.AddTo(attackerFactory, entity => BufferedAttackTargetProvider.Simple, Layers.REAL, Faction.Any).SkipEmptyAttackPreset();


            attackedFactory = new EntityFactory();
            Transform.AddTo(attackedFactory, Layers.REAL, 0);
            FactionComponent.AddTo(attackedFactory, Faction.Environment);
            Stats.AddTo(attackedFactory, Registry.Global.Stats._map);
            Attackable.AddTo(attackedFactory, Attackness.ALWAYS);
        }