예제 #1
0
    public void ControlUnit(FormationUnit prisoner, FormationUnit controller, int duration)
    {
        RaidSceneManager.BattleGround.Controls.Add(new ControlRecord(prisoner, controller, duration));
        prisoner.Formation.DeleteUnit(prisoner, false);
        prisoner.Character.GetStatusEffect(StatusType.Guarded).ResetStatus();
        prisoner.Character.GetStatusEffect(StatusType.Guard).ResetStatus();
        Round.OrderedUnits.RemoveAll(unit => unit == prisoner);

        prisoner.Team = controller.Team;
        prisoner.transform.SetParent(controller.Party.transform, true);
        prisoner.Party     = controller.Party;
        prisoner.Formation = controller.Formation;
        prisoner.CombatInfo.PrepareForBattle(prisoner.CombatInfo.CombatId);
        prisoner.InstantFlip();
        prisoner.SetMoveSmoothTime(0.1f);

        if (prisoner.Formation.AvailableFreeSpace >= prisoner.Size)
        {
            prisoner.Formation.SpawnUnit(prisoner, 4);
        }
        else if (prisoner.Formation.AvailableSummonSpace >= prisoner.Size)
        {
            var purgingCandidates = new List <FormationUnit>(prisoner.Formation.party.Units);
            purgingCandidates.Sort((x, y) =>
            {
                if (Mathf.Abs(x.Rank - 4) == Mathf.Abs(y.Rank - 4))
                {
                    return(0);
                }
                if (Mathf.Abs(x.Rank - 4) < Mathf.Abs(y.Rank - 4))
                {
                    return(1);
                }
                else
                {
                    return(-1);
                }
            });

            for (int i = purgingCandidates.Count - 1; i >= 0; i--)
            {
                if (purgingCandidates[i].Character.IsMonster && purgingCandidates[i].Character.BattleModifiers.CanBeSummonRank)
                {
                    RaidSceneManager.Instanse.SummonPurging(purgingCandidates[i]);
                    if (prisoner.Formation.AvailableFreeSpace >= prisoner.Size)
                    {
                        prisoner.Formation.SpawnUnit(prisoner, 4);
                        prisoner.OverlaySlot.UpdateOverlay();
                        return;
                    }
                }
            }
            Debug.LogError("Not enough control space for " + prisoner.name);
        }
        else
        {
            Debug.LogError("Not enough control space for " + prisoner.name);
        }
        prisoner.OverlaySlot.UpdateOverlay();
    }