Пример #1
0
    public void Apply(EntityBehaviour sender, Vector2 target)
    {
        foreach (Vector2 cell in sender.GetAoeOfEffect(this, target))
        {
            GameObject entity = CustomGrid.instance.GetEntityOnCell((int)cell.x, (int)cell.y);
            List <KeyValuePair <Effect, EntityBehaviour> > entityEffects = new List <KeyValuePair <Effect, EntityBehaviour> >();
            if (entity != null)
            {
                entityEffects = entity.GetComponent <EntityBehaviour>().character.effects;
                entityEffects.Add(new KeyValuePair <Effect, EntityBehaviour>(this.MemberwiseClone() as Effect, sender));
            }

            if ((_type == EffectType.Physical ||
                 _type == EffectType.Magic ||
                 _type == EffectType.Heal) &&
                entity != null)    // CurrentHP
            {
                entityEffects[entityEffects.Count - 1].Key.Resolve(sender, reciever: entity.GetComponent <EntityBehaviour>());
                if (entityEffects[entityEffects.Count - 1].Key.currentTurn >= entityEffects[entityEffects.Count - 1].Key.effects.Count)
                {
                    entityEffects.RemoveAt(entityEffects.Count - 1);
                }
            }
            else if ((_type == EffectType.Create || _type == EffectType.Jump) && entity == null) // Create
            {
                entityEffects = sender.character.effects;
                entityEffects.Add(new KeyValuePair <Effect, EntityBehaviour>(this.MemberwiseClone() as Effect, sender));

                entityEffects[entityEffects.Count - 1].Key.Resolve(sender, target: cell);
                if (entityEffects[entityEffects.Count - 1].Key.currentTurn >= entityEffects[entityEffects.Count - 1].Key.effects.Count)
                {
                    entityEffects.RemoveAt(entityEffects.Count - 1);
                }
            }
            else if (_type == EffectType.Move && entity != null) // Move
            {
                if (target.Equals(cell))
                {
                    entityEffects[entityEffects.Count - 1].Key.Resolve(sender, reciever: entity.GetComponent <EntityBehaviour>(), target: new Vector2(sender.x, sender.y));
                }
                else
                {
                    entityEffects[entityEffects.Count - 1].Key.Resolve(sender, reciever: entity.GetComponent <EntityBehaviour>(), target: target);
                }
                if (entityEffects[entityEffects.Count - 1].Key.currentTurn >= entityEffects[entityEffects.Count - 1].Key.effects.Count)
                {
                    entityEffects.RemoveAt(entityEffects.Count - 1);
                }
            }
            else if (_type == EffectType.Charac && entity != null) // Charac
            {
                entityEffects[entityEffects.Count - 1].Key.Resolve(sender, reciever: entity.GetComponent <EntityBehaviour>());
            }
            else if (_type == EffectType.Transpose && entity != null)
            {
                entityEffects[entityEffects.Count - 1].Key.Resolve(sender, reciever: entity.GetComponent <EntityBehaviour>());
                if (entityEffects[entityEffects.Count - 1].Key.currentTurn >= entityEffects[entityEffects.Count - 1].Key.effects.Count)
                {
                    entityEffects.RemoveAt(entityEffects.Count - 1);
                }
            }
        }
    }