示例#1
0
    public List <Creature> FetchTargetsFront()
    {
        List <Creature> targets = new List <Creature>();

        FightGrid grid = m_proto.TargetGridFace ?
                         OwnerSkill.OwnerCreature.FGrid.Face :
                         OwnerSkill.OwnerCreature.FGrid;

        int c = OwnerSkill.OwnerCreature.Index.X + (OwnerSkill.OwnerCreature.Proto.Dim.X - 1) / 2;

        for (int y = 0; y < FightGrid.UnitCount.Y; ++y)
        {
            for (int i = 0; i < s_fetch_offset.Length; ++i)
            {
                int curt_x = s_fetch_offset[i] + c;
                if (curt_x < OwnerSkill.OwnerCreature.Index.X || curt_x >= OwnerSkill.OwnerCreature.Index.X + OwnerSkill.OwnerCreature.Proto.Dim.X)
                {
                    break;
                }

                FightGrid.Unit u = grid.Units[y, curt_x];
                if (u.Creature == null || u.Creature.State == Creature.StateType.Death)
                {
                    continue;
                }
                else
                {
                    targets.Add(u.Creature);
                    return(targets);
                }
            }
        }
        for (int i = 0; i < s_fetch_offset.Length; ++i)
        {
            int curt_x = s_fetch_offset[i] + c;
            if (curt_x < 0 || curt_x >= FightGrid.UnitCount.X)
            {
                continue;
            }

            for (int y = 0; y < FightGrid.UnitCount.Y; ++y)
            {
                FightGrid.Unit u = grid.Units[y, curt_x];
                if (u.Creature == null || u.Creature.State == Creature.StateType.Death)
                {
                    continue;
                }
                else
                {
                    targets.Add(u.Creature);
                    return(targets);
                }
            }
        }
        return(null);
    }
示例#2
0
    public void Create(FightGridView grid, FightGrid.Unit unit)
    {
        m_grid = grid;
        m_unit = unit;

        m_rc_world = new Rect(m_unit.Position * Launcher.SpriteScale, Vector2.one * FightGrid.UnitSize * Launcher.SpriteScale);
        m_rc_world.position -= m_rc_world.size / 2;

        BodyColor = new Color(1, 1, 1, 0);
    }
示例#3
0
    public void Create(FightGridView grid, FightGrid.Unit unit)
    {
        m_grid           = grid;
        m_unit           = unit;
        gameObject.layer = (int)UnityLayer.UI;

        m_rc_world           = new Rect(m_unit.Position, Vector2.one * FightGrid.UnitSize);
        m_rc_world.position -= m_rc_world.size / 2;

        //BodyColor = new Color(1, 1, 1, 0);
    }
示例#4
0
    public bool Replace(Creature crt, Int2D dest_pt)
    {
        Int2D dest_offset;

        if (!CanBeReplace(crt, dest_pt, out dest_offset))
        {
            return(false);
        }

        Debug.Log(dest_offset.ToString());

        Int2D src_pt = crt.Index;

        Dictionary <Creature, Int2D> dics = new Dictionary <Creature, Int2D>();

        for (int x = 0; x < crt.Proto.Dim.X; ++x)
        {
            for (int y = 0; y < crt.Proto.Dim.Y; ++y)
            {
                Int2D          dest = new Int2D(dest_pt.X + x, dest_pt.Y + y);
                FightGrid.Unit u    = Units[dest.Y, dest.X];
                if (u.Creature == null || u.Creature == crt)
                {
                    continue;
                }
                if (dics.ContainsKey(u.Creature))
                {
                    continue;
                }
                dics[u.Creature] = u.Creature.Index - dest_offset;
            }
        }

        LeaveCreature(crt);
        foreach (Creature c in dics.Keys)
        {
            LeaveCreature(c);
        }

        EnterCreature(crt, dest_pt);
        foreach (KeyValuePair <Creature, Int2D> pair in dics)
        {
            EnterCreature(pair.Key, pair.Value);
        }

        return(true);
    }
示例#5
0
    public bool CanBeReplace(Creature crt, Int2D dest, out Int2D dest_offset)
    {
        dest_offset = new Int2D(-1, -1);

        // find all creature and calc bounder in area of dest
        Int2D dest_min = new Int2D(+int.MaxValue, +int.MaxValue);
        Int2D dest_max = new Int2D(-int.MaxValue, -int.MaxValue);
        HashSet <Creature> dest_crts     = new HashSet <Creature>();
        HashSet <Int2D>    will_occupied = new HashSet <Int2D>();

        for (int x = 0; x < crt.Proto.Dim.X; ++x)
        {
            for (int y = 0; y < crt.Proto.Dim.Y; ++y)
            {
                Int2D dest_curt = new Int2D(dest.X + x, dest.Y + y);
                will_occupied.Add(dest_curt);

                FightGrid.Unit dest_u = Units[dest_curt.Y, dest_curt.X];
                if (dest_u.Creature == null || dest_u.Creature == crt)
                {
                    continue;
                }

                dest_min.X = Mathf.Min(dest_min.X, dest_u.Creature.Index.X);
                dest_min.Y = Mathf.Min(dest_min.Y, dest_u.Creature.Index.Y);
                dest_max.X = Mathf.Max(dest_max.X, dest_u.Creature.Index.X + dest_u.Creature.Proto.Dim.X);
                dest_max.Y = Mathf.Max(dest_max.Y, dest_u.Creature.Index.Y + dest_u.Creature.Proto.Dim.Y);
                if (!dest_crts.Contains(dest_u.Creature))
                {
                    dest_crts.Add(dest_u.Creature);
                }
            }
        }

        List <Int2D> for_checks = new List <Int2D>();

        for_checks.Add(new Int2D(0, 0));
        for (int x = 0; x < crt.Proto.Dim.X; ++x)
        {
            for (int y = 0; y < crt.Proto.Dim.Y; ++y)
            {
                for_checks.Add(new Int2D(x, y));
            }
        }
        for (int x = dest_min.X; x < dest_max.X; ++x)
        {
            for (int y = dest_min.Y; y < dest_max.Y; ++y)
            {
                for_checks.Add(new Int2D(x - crt.Index.X, y - crt.Index.Y));
            }
        }


        Unit[,] temp_unit = SnapUnits();
        foreach (Unit u in temp_unit)
        {
            if (dest_crts.Contains(u.Creature) || u.Creature == crt)
            {
                u.Creature = null;
            }
        }

        for (int x = 0; x < crt.Proto.Dim.X; ++x)
        {
            for (int y = 0; y < crt.Proto.Dim.Y; ++y)
            {
                Int2D curt = dest + new Int2D(x, y);
                if (curt.X >= FightGrid.UnitCount.X || curt.Y >= FightGrid.UnitCount.Y)
                {
                    return(false);
                }
                temp_unit[curt.Y, curt.X].Creature = crt;
            }
        }

        for (int i = 0; i < for_checks.Count; ++i)
        {
            // check possible in curt orig
            bool  can_fit   = true;
            Int2D curt_orig = new Int2D(crt.Index.X + for_checks[i].X, crt.Index.Y + for_checks[i].Y);
            foreach (Creature dest_crt in dest_crts)
            {
                for (int dx = 0; dx < dest_crt.Proto.Dim.X; ++dx)
                {
                    for (int dy = 0; dy < dest_crt.Proto.Dim.Y; ++dy)
                    {
                        Int2D check_pt = Int2D.zero;
                        if (i == 0)
                        {
                            Int2D offset = new Int2D(dest_crt.Index.X - dest.X, dest_crt.Index.Y - dest.Y);
                            check_pt = new Int2D(curt_orig.X + dx + offset.X, curt_orig.Y + dy + offset.Y);
                        }
                        else
                        {
                            Int2D offset = new Int2D(dest_crt.Index.X - dest_min.X, dest_crt.Index.Y - dest_min.Y);
                            check_pt = new Int2D(curt_orig.X + dx + offset.X, curt_orig.Y + dy + offset.Y);
                        }
                        if (check_pt.X < 0 || check_pt.Y < 0 || check_pt.X >= FightGrid.UnitCount.X || check_pt.Y >= FightGrid.UnitCount.Y)
                        {
                            can_fit = false;
                            break;
                        }
                        FightGrid.Unit check = temp_unit[check_pt.Y, check_pt.X];
                        //if (check.Creature == null || (check.Creature == crt && !will_occupied.Contains(check_pt)) ||
                        //    dest_crts.Contains(check.Creature))
                        if (check.Creature == null)
                        {
                            continue;
                        }
                        else
                        {
                            can_fit = false;
                            break;
                        }
                    }
                    if (!can_fit)
                    {
                        break;
                    }
                }
                if (!can_fit)
                {
                    break;
                }
            }
            if (can_fit)
            {
                dest_offset = (i == 0) ? dest - crt.Index : dest - ((crt.Index + for_checks[i]) + (dest - dest_min));
                return(true);
            }
        }
        return(false);
    }