Exemplo n.º 1
0
    /// <summary>
    /// Called when an Entity is hit by the Attack.
    /// </summary>
    /// <param name="target">hitted Entity</param>
    public virtual void onHit(Entity target)
    {
        if (canBeHit(target))
        {
            //Set up the new state of hitted target.
            target.State = Utilities.state.Hit;
            hittedEntities.Add(target);
            target.Animator.Play("Hit");
            if (target.State == Utilities.state.Edge)
            {
                target.BoxCollider.enabled = true;
            }
            target.RigidBody.gravityScale = target.getGravityAmount();
            target.RigidBody.velocity     = new Vector2(0, 0);

            //Deals the damage to target.
            float totalDamage    = damage;
            float startingHealth = target.getLife();
            if (chargeable)
            {
                totalDamage = damage + ((user.getChargeAmount() * damage) / 2);
                user.setAttackCharge(0);
            }
            target.receiveDamage(totalDamage);
            float lostLife   = target.getMaxLife() - target.getLife();
            float mappedLife = Map(lostLife, target.getMaxLife());
            if (user is Character)
            {
                chargeEnergy(user, totalDamage / 2);
            }


            if (stuns)// If Attack stuns.
            {
                if (stuns)
                {
                    target.StartCoroutine(target.hitStun(stunTime));
                }
                else
                {
                    target.StartCoroutine(target.hitStun(60f));
                }
            }
            else
            {
                if (target.getLife() == 0)//finisher hit
                {
                    target.StartCoroutine(target.receiveHit(25, 80, this));
                }
                else
                {
                    //normal hit
                    float totalKnockBack = Utilities.calculateKnockBack(mappedLife, totalDamage, target.RigidBody.mass, knockBack);
                    target.StartCoroutine(target.receiveHit(totalDamage, totalKnockBack, this));
                }
            }
            user.StartCoroutine(user.hitLag(totalDamage, false));
            GameManager.Instance.currentFight.onEntityHit(user, target, (int)totalDamage);
        }
    }
Exemplo n.º 2
0
    // Preform the action
    public override void Run(Entity entity)
    {
        entity.StopAllCoroutines();
        // We check to see if the action is still valid
        if (!Valid(entity))
        {
            entity.StartCoroutine(PostRun(entity));
            return;
        }

        // Generate the route to the tile
        List <EnvironmentTile> route = Environment.instance.SolveNeighbour(entity.CurrentPosition, environmentTile);

        // If we are null, we must be by the tile
        if (route == null)
        {
            entity.StartCoroutine(DoAction(entity, environmentTile));
        }
        else if (route.Count > 0) // we must be able to path to the tile, walk to the tile
        {
            entity.StartCoroutine(DoWalkAndCollection(entity, route, environmentTile));
        }
        else // We can no path to the tile, so post run
        {
            entity.StartCoroutine(PostRun(entity));
        }
    }
Exemplo n.º 3
0
    protected void downKnockBackEntity(Entity target, float totalKnockBack)
    {
        float camf = 0.1f;

        if (totalKnockBack > 30)
        {
            camf = 0.5f;
        }
        user.cam.transform.DOShakePosition(0.1f, camf, 1, 90, false, true);
        target.RigidBody.velocity = new Vector2(0, 0);

        Vector2 forceDirection = (target.transform.position - user.transform.position);
        float   forceX;

        if (forceDirection.x > 0.5f)
        {
            forceX = totalKnockBack * 0.5f;
        }
        else if (forceDirection.x < -0.5f)
        {
            forceX = totalKnockBack * -0.5f;
        }
        else
        {
            forceX = forceDirection.x * totalKnockBack;
        }
        target.RigidBody.AddForce(new Vector2(forceX, -totalKnockBack), ForceMode2D.Impulse);

        target.StartCoroutine(target.hitStun(totalKnockBack));
    }
Exemplo n.º 4
0
    IEnumerator Activation(Entity source, bool isLoop = false)
    {
        var points = (source as Enemy).actionPoints;

        for (int i = 0; i < actions.Count; i++)
        {
            if (actions[i].Check(source))
            {
                actions[i].Do(source);
                if (actions[i].loopable)
                {
                    i--;
                }
            }
            while (!(source as Enemy).ready)
            {
                yield return(null);
            }
            yield return(new WaitForSeconds(0.15f));
        }
        var newPoints = (source as Enemy).actionPoints;

        if (points != newPoints)
        {
            isLoop = false;
        }
        if (loopable && !isLoop)
        {
            source.StartCoroutine(Activation(source, true));
        }
        else
        {
            (source as Enemy).done = true;
        }
    }
Exemplo n.º 5
0
    public override void OnEnter(int tX, int tY, Entity entity)
    {
        ushort   data = Map.GetTile(1, tX, tY).Data;
        Vector2i dir  = Vector2i.zero;

        switch (data)
        {
        case 1:
            dir = Vector2i.right;
            break;

        case 2:
            dir = Vector2i.down;
            break;

        case 3:
            dir = Vector2i.left;
            break;

        default:
            dir = Vector2i.up;
            break;
        }

        Vector2i start = new Vector2i(tX, tY);
        Vector2i end   = Utils.GetLineEnd(start, dir);

        if (end.Equals(start))
        {
            return;
        }

        entity.wait = true;
        entity.StartCoroutine(entity.SlideTo(end, dir));
    }
Exemplo n.º 6
0
    public static void calculateDirectionForce(Entity target, ThrowableItem it)
    {
        target.receiveDamage(it.getDamage());
        Rigidbody2D trbd          = target.GetComponent <Rigidbody2D>();
        Rigidbody2D itrbd         = it.GetComponent <Rigidbody2D>();
        float       lostLife      = target.getMaxLife() - target.getLife();
        float       itemknockBack = calculateKnockBack(lostLife, it.getDamage(), itrbd.mass, it.getKnockBack());

        switch (it.getDirection())
        {
        case Utilities.direction.Up: trbd.AddForce(new Vector2(0f, itemknockBack * 1.5f), ForceMode2D.Impulse); break;

        case Utilities.direction.Down: trbd.AddForce(new Vector2(0f, -itemknockBack), ForceMode2D.Impulse); break;

        case Utilities.direction.Left: trbd.AddForce(new Vector2(-itemknockBack, itemknockBack), ForceMode2D.Impulse); break;

        case Utilities.direction.Right: trbd.AddForce(new Vector2(itemknockBack, itemknockBack), ForceMode2D.Impulse); break;

        case Utilities.direction.UpLeft: trbd.AddForce(new Vector2(-itemknockBack, itemknockBack * 1.5f), ForceMode2D.Impulse); break;

        case Utilities.direction.UpRight: trbd.AddForce(new Vector2(itemknockBack, itemknockBack * 1.5f), ForceMode2D.Impulse); break;

        case Utilities.direction.DownLeft: trbd.AddForce(new Vector2(-itemknockBack, -itemknockBack), ForceMode2D.Impulse); break;

        case Utilities.direction.DownRight: trbd.AddForce(new Vector2(itemknockBack, -itemknockBack), ForceMode2D.Impulse); break;
        }

        target.StartCoroutine(target.hitStun(itemknockBack));
    }
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        Vector2Int step = GetMapStepForMovement(animator);

        Entity     entity         = animator.GetComponent <Entity>();
        Vector2Int mapDestination = entity.mapPosition + step;

        // Get the destination tile, if present
        Tile destinationTile;
        int  entitiesOnTile = 0;

        if (Map.Tiles.TryGetValue(mapDestination, out destinationTile))
        {
            entitiesOnTile = destinationTile.EntitiesOnTile.Count;
        }

        // Get the right coroutine to use, if any
        IEnumerator movementCoroutine = null;

        if (destinationTile != null && entitiesOnTile < 2 && entity.CanMoveTo(mapDestination, destinationTile))
        {
            animator.SetFloat("movement_speed_multiplier", 1);

            bool destinationTileIsEmpty = entitiesOnTile <= 0;
            if (destinationTileIsEmpty)
            {
                movementCoroutine = entity.StepTo(mapDestination, Vector2.zero);
            }
            else
            {
                // Calculate the entity's own offset in the tile
                Vector2 ownOffset = (Map.ConvertToWorldPosition(mapDestination) - (Vector2)animator.transform.position) * -entity.offsetDistanceWhenMovingToSide;
                // Tell every other entity on the tile their new offset based on their desired offset distance
                destinationTile.EntitiesOnTile.ForEach(opposingEntity => {
                    opposingEntity.offsetInTileWhenMovingToSide = -ownOffset.normalized * opposingEntity.offsetDistanceWhenMovingToSide;
                });
                movementCoroutine = entity.StepTo(mapDestination, ownOffset);
            }
            // If the destination tile isn't empty we're already jumping to the side
            entity.isAtSideOfTile = !destinationTileIsEmpty;
        }
        // If the player is not at the side of the tile (i.e. the tile is empty), make a blocked step
        // Blocked steps are forbidden on non-empty tiles due to glitchy behaviour
        else if (entity is Player && !entity.isAtSideOfTile)
        {
            Player player = entity as Player;
            animator.SetFloat("movement_speed_multiplier", 1 / player.blockedStepTime / 2);
            movementCoroutine = player.StepBlockedTo(mapDestination);
        }
        // If the entity can't make a blocked step, cancel the move state immediately
        else
        {
            animator.SetTrigger("cancel_movement");
        }
        if (movementCoroutine != null)
        {
            entity.StartCoroutine(movementCoroutine);
        }
    }
Exemplo n.º 8
0
    // On the action run
    public override void Run(Entity entity)
    {
        // If the environment tile is null, then somehow the state was accessed, break
        if (environmentTile == null)
        {
            return;
        }

        // Calculate the route to the target tile
        List <EnvironmentTile> route = Environment.instance.Solve(entity.CurrentPosition, environmentTile);

        entity.StopAllCoroutines();
        // Start the entity movement
        entity.StartCoroutine(DoGoToLocal(entity, entity.GetMovmentSpeed(), route));
    }
Exemplo n.º 9
0
    public override void OnEnter(int tX, int tY, Entity entity)
    {
        Vector2i start = new Vector2i(tX, tY);

        List <Vector2i> dirs = new List <Vector2i>(4);

        dirs.Add(Vector2i.left);
        dirs.Add(Vector2i.right);
        dirs.Add(Vector2i.up);
        dirs.Add(Vector2i.down);

        Utils.ShuffleList <Vector2i>(dirs);

        Vector2i dir = Vector2i.zero;

        for (int i = dirs.Count - 1; i >= 0; i--)
        {
            Vector2i next = start + dirs[i];

            if (!Map.GetTileTypeSafe(1, next.x, next.y).IsPassable(next.x, next.y))
            {
                dirs.RemoveAt(i);
            }
            else
            {
                dir = dirs[i];
                break;
            }
        }

        if (dir.Equals(Vector2i.zero))
        {
            return;
        }

        Vector2i end = Utils.GetLineEnd(start, dir);

        if (end.Equals(start))
        {
            return;
        }

        entity.wait = true;
        entity.StartCoroutine(entity.SlideTo(end, dir));
    }
Exemplo n.º 10
0
    protected void sideKnockBackEntity(Entity target, float totalKnockBack, Utilities.direction direction)
    {
        float camf = 0.1f;

        if (totalKnockBack > 30)
        {
            camf = 0.5f;
        }
        user.cam.transform.DOShakePosition(0.1f, camf, 1, 90, false, true);

        target.RigidBody.velocity = new Vector2(0, 0);
        float forceY = 0;

        if (target.State == Utilities.state.Air)
        {
            Vector2 forceDirection = (target.transform.position - user.transform.position);
            if (forceDirection.y > 0.5f)
            {
                forceY = totalKnockBack * 0.5f;
            }
            else if (forceDirection.y < -0.5f)
            {
                forceY = totalKnockBack * -0.5f;
            }
            else
            {
                forceY = forceDirection.y * totalKnockBack;
            }
        }
        else
        {
            forceY = totalKnockBack / 2;
        }

        if (direction == Utilities.direction.Right)
        {
            target.RigidBody.AddForce(new Vector2(totalKnockBack, forceY), ForceMode2D.Impulse);
        }
        else
        {
            target.RigidBody.AddForce(new Vector2(-totalKnockBack, forceY), ForceMode2D.Impulse);
        }
        target.StartCoroutine(target.hitStun(totalKnockBack));
    }
Exemplo n.º 11
0
    public static void AddExplosionForce(Rigidbody2D body, float expForce, Vector3 expPosition, float expRadius, Item it)
    {
        Entity target = body.gameObject.GetComponent <Entity>();

        target.receiveDamage(it.getDamage());
        expForce = expForce * 3;
        var   dir  = (body.transform.position - expPosition);
        float calc = 1 - (dir.magnitude / expRadius);

        if (calc <= 0)
        {
            calc = 0;
        }
        body.AddForce(dir.normalized * expForce * calc, ForceMode2D.Impulse);
        float lostLife      = target.getMaxLife() - target.getLife();
        float totalKnckBack = calculateKnockBack(lostLife, it.getDamage(), it.getRigidBody().mass, it.getKnockBack());

        target.StartCoroutine(body.GetComponent <Entity>().hitStun(totalKnckBack));
    }
Exemplo n.º 12
0
    static int StartCoroutine(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        Type[] types0 = { typeof(Entity), typeof(string) };
        Type[] types1 = { typeof(Entity), typeof(IEnumerator) };

        if (count == 2 && LuaScriptMgr.CheckTypes(L, types0, 1))
        {
            Entity    obj  = LuaScriptMgr.GetNetObject <Entity>(L, 1);
            string    arg0 = LuaScriptMgr.GetString(L, 2);
            Coroutine o    = obj.StartCoroutine(arg0);
            LuaScriptMgr.PushObject(L, o);
            return(1);
        }
        else if (count == 2 && LuaScriptMgr.CheckTypes(L, types1, 1))
        {
            Entity      obj  = LuaScriptMgr.GetNetObject <Entity>(L, 1);
            IEnumerator arg0 = LuaScriptMgr.GetNetObject <IEnumerator>(L, 2);
            Coroutine   o    = obj.StartCoroutine(arg0);
            LuaScriptMgr.PushObject(L, o);
            return(1);
        }
        else if (count == 3)
        {
            Entity    obj  = LuaScriptMgr.GetNetObject <Entity>(L, 1);
            string    arg0 = LuaScriptMgr.GetLuaString(L, 2);
            object    arg1 = LuaScriptMgr.GetVarObject(L, 3);
            Coroutine o    = obj.StartCoroutine(arg0, arg1);
            LuaScriptMgr.PushObject(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: Entity.StartCoroutine");
        }

        return(0);
    }
Exemplo n.º 13
0
 public virtual bool ChangeState(EntityState nextState)
 {
     if (nextState == null)
     {
         return(false);
     }
     if (State != null && !State.OnExit(Entity, nextState, this))
     {
         return(false);
     }
     if (!nextState.OnEnter(Entity, State, this))
     {
         return(false);
     }
     if (currentStateCoroutine != null)
     {
         Entity.StopCoroutine(currentStateCoroutine);
     }
     state = nextState;
     currentStateCoroutine = Entity.StartCoroutine(State.Begin(Entity, this));
     return(true);
 }
 /// <summary>
 /// Called when Character has Hit something.
 /// </summary>
 /// <param name="collision"></param>
 public void hit(Collider2D collision)
 {
     if (collision.GetComponentInParent <Entity>() != null) //if hits an Entity.
     {
         Entity target = collision.GetComponentInParent <Entity>();
         if (target.state != Utilities.state.Blocking)//not blocking, realize hit.
         {
             if (currentAttack != Utilities.attackType.None)
             {
                 attacks[(int)currentAttack].onHit(target);
             }
         }
         else
         {
             if (user.state != Utilities.state.Ultimate)// if blocking and not ultimate, parry effect(stun).
             {
                 user.stopAttacking();
                 user.state = Utilities.state.Hit;
                 user.RigidBody.velocity = new Vector2(0, 0);
                 user.Animator.Play("Hit");
                 user.StartCoroutine(user.hitStun(25f));
             }
             ((Character)target).onBlock();
         }
     }
     else if (collision.GetComponentInParent <Ball>())
     {
         Ball ballItem = collision.GetComponentInParent <Ball>();
         if (currentAttack != Utilities.attackType.None)
         {
             float damage      = attacks[(int)currentAttack].damage;
             float attackKnock = attacks[(int)currentAttack].knockBack;
             float knockBack   = Utilities.calculateKnockBack(50, damage, ballItem.getRigidBody().mass, attackKnock);
             ballItem.addForceByAttack(user, knockBack);
         }
     }
 }
Exemplo n.º 15
0
 private void OnStateEntered(object sender, System.EventArgs e)
 {
     Entity.StartCoroutine(WaitAnimation());
 }
Exemplo n.º 16
0
    /// <summary>
    /// 스킬을 사용한다.
    /// </summary>
    /// <param name="obj">스킬의 사용자</param>
    public override void Activate(GameObject obj)
    {
        Entity entity = obj.GetComponent <Entity>();

        entity.StartCoroutine(Attack(obj, damage, range, 1f, "Bash"));
    }
    public override void execute(Entity entity)
    {
        Body2dEntity body2dEntity = (Body2dEntity)entity;

        entity.StartCoroutine(body2dEntity.MoveTo(moveToDestination));
    }
Exemplo n.º 18
0
 private void StateGame_Entered(object sender, System.EventArgs e)
 {
     run = true;
     Entity.StartCoroutine(Spawner());
     SetAllSlotActive(true);
 }
Exemplo n.º 19
0
    public override void Activate(GameObject obj)
    {
        Entity entity = obj.GetComponent <Entity>();

        entity.StartCoroutine(Attack(obj, 0, 2, 0.2f, "Attack"));
    }
Exemplo n.º 20
0
    public override void execute(Entity entity)
    {
        Body2dEntity body2dEntity = (Body2dEntity)entity;

        entity.StartCoroutine(body2dEntity.MoveTo(moveToDestination));
    }
Exemplo n.º 21
0
    public override void execute(Entity entity)
    {
        Body2dEntity body2dEntity = (Body2dEntity)entity;

        entity.StartCoroutine(body2dEntity.MoveBy(moveByX, moveByY));
    }
Exemplo n.º 22
0
 public void Activate(Entity source)
 {
     source.StartCoroutine(Activation(source));
 }
Exemplo n.º 23
0
        public override void TakeAction(Entity entity)
        {
            if (SkillType == "RotateAttackSkill")
            {
                //TODO 技能持续时间暂定1s,等待完善,调整后记得调weapon上的动画时间
                float SkillInternal = 3f;

                // 暂停自动攻击
                StopAutoAttackFragment stopAutoAttackFragment = new StopAutoAttackFragment(SkillInternal);
                stopAutoAttackFragment.TakeEffect(entity);

                // 范围攻击
                AreaAttackFragment areaAttackFragment = new AreaAttackFragment();
                areaAttackFragment.Damage        = 35;
                areaAttackFragment.SkillInternal = SkillInternal;
                areaAttackFragment.HitPower      = 0.4f;
                areaAttackFragment.TakeEffect(entity);

                // 移速增加
                SpeedChangeMoveFragment speedChangeMoveFragment = new SpeedChangeMoveFragment();
                speedChangeMoveFragment.InternalTime = SkillInternal;
                speedChangeMoveFragment.TakeEffect(entity);

                // 动画表示
                RotateAttackAnimatorFragment rotateAttackAnimatorFragment = new RotateAttackAnimatorFragment();
                rotateAttackAnimatorFragment.InteralTime = SkillInternal;
                rotateAttackAnimatorFragment.TakeEffect(entity);

                // 音效表示
                AudioCreateFragment audioPlayFragment = new AudioCreateFragment();
                audioPlayFragment.AudioName    = SkillType;
                audioPlayFragment.PlayInternal = 0;
                audioPlayFragment.TakeEffect(entity);
                audioPlayFragment.PlayInternal = SkillInternal / 2;
                audioPlayFragment.TakeEffect(entity);

                //格挡子弹

                entity.transform.GetChild(2).gameObject.SetActive(true);
                entity.StartCoroutine(CloseCircleCollider(SkillInternal, entity));
            }
            else if (SkillType == "BombSkill")
            {
                // 动画展示
                AnimatorParameterFragment animatorFragment = new AnimatorParameterFragment();
                animatorFragment.Animator = entity.transform.GetChild(0).GetComponent <Animator>();
                animatorFragment.Name     = "Throw";
                animatorFragment.TakeEffect();

                // 扔一个水弹
                BombFragment bombFragement = new BombFragment();
                bombFragement.AttackTag   = "Enemies";
                bombFragement.BulletSpeed = 1f;
                bombFragement.TargetPos   = TouchPoint;
                bombFragement.Damage      = 30;
                bombFragement.TakeEffect(entity);

                // 音效表示
                AudioCreateFragment audioPlayFragment = new AudioCreateFragment();
                audioPlayFragment.AudioName    = SkillType;
                audioPlayFragment.PlayInternal = 0f;
                audioPlayFragment.TakeEffect(entity);
            }
            else if (SkillType == "RushSkill")
            {
                int SkillInternal = 1;

                // 冲刺
                MoveTowardFragment moveTowardFragment = new MoveTowardFragment();
                moveTowardFragment.InternalTime = SkillInternal;
                moveTowardFragment.Direction    = TouchPoint - new Vector2(entity.transform.position.x, entity.transform.position.y);
                moveTowardFragment.Speed        = 0.4f;
                moveTowardFragment.TakeEffect(entity);

                // 暂停移动输入
                StopPlayerMovementFragment stopPlayerMovementFragment = new StopPlayerMovementFragment(SkillInternal);
                stopPlayerMovementFragment.TakeEffect(entity);

                // 暂停自动攻击
                StopAutoAttackFragment stopAutoAttackFragment = new StopAutoAttackFragment(SkillInternal);
                stopAutoAttackFragment.TakeEffect(entity);

                // 将武器指向冲刺方向(武器附上击退效果)
                RushAttackFragment rushFragment = new RushAttackFragment();
                rushFragment.RushDir      = TouchPoint - (Vector2)entity.transform.position;
                rushFragment.InternalTime = SkillInternal;
                rushFragment.TakeEffect(entity);

                // 武器动画
                RushAttackAnimatorFragment weaponAnimatorFragment = new RushAttackAnimatorFragment();
                weaponAnimatorFragment.InteralTime = SkillInternal;
                weaponAnimatorFragment.TakeEffect(entity);

                // 人物动画
                AnimatorParameterFragment animatorFragment = new AnimatorParameterFragment();
                animatorFragment.Animator = entity.transform.GetChild(0).GetComponent <Animator>();
                animatorFragment.Name     = "Rush";
                animatorFragment.TakeEffect();

                // 音效表示
                AudioCreateFragment audioPlayFragment = new AudioCreateFragment();
                audioPlayFragment.AudioName    = SkillType;
                audioPlayFragment.PlayInternal = 0f;
                audioPlayFragment.TakeEffect(entity);

                entity.transform.GetChild(2).gameObject.SetActive(true);
                entity.StartCoroutine(CloseCircleCollider(SkillInternal, entity));
            }
            else
            {
                throw new ArgumentException("SkillType is out of consider.");
            }
        }
Exemplo n.º 24
0
 public void Destroy()
 {
     gameObject.SetActive(false);
     DeathHandler.StartCoroutine(DeathCoroutine());
 }
Exemplo n.º 25
0
 public override void Fire(Entity sourceEntity, Entity targetEntity, Vector3 targetPosition)
 {
     sourceEntity.StartCoroutine(FireLasersAtTargetCoroutine(sourceEntity, targetEntity, targetPosition));
 }
    public override void execute(Entity entity)
    {
        Body2dEntity body2dEntity = (Body2dEntity)entity;

        entity.StartCoroutine(body2dEntity.MoveBy(moveByX, moveByY));
    }