Exemple #1
0
        private int ComputeGameStateValue(GameState state)
        {
            if (state.losers.ToList().Contains(ID))
            {
                return(int.MinValue);
            }
            else if (state.losers.ToList().Contains(battle.WaitingPlayer.ID))
            {
                return(int.MaxValue);
            }
            int                   rating     = 0;
            List <Fruiton>        fruitons   = state.fruitons.CastToList <Fruiton>();
            IEnumerable <Fruiton> kings      = fruitons.Where(fruiton => fruiton.type == (int)FruitonType.KING);
            Fruiton               aiKing     = kings.First(fruiton => fruiton.owner.id == ID);
            Fruiton               playerKing = kings.First(fruiton => fruiton.owner.id != ID);

            foreach (Fruiton fruiton in fruitons)
            {
                bool  isFruitonAi                = fruiton.owner.id == ID;
                int   sign                       = isFruitonAi ? 1 : -1;
                Point enemyKingPosition          = isFruitonAi ? playerKing.position : aiKing.position;
                int   xDiff                      = fruiton.position.x - enemyKingPosition.x;
                int   yDiff                      = fruiton.position.y - enemyKingPosition.y;
                int   distanceToEnemyKingSquared = xDiff * xDiff + yDiff * yDiff;
                rating += sign * (10000 * (fruiton.currentAttributes.hp + fruiton.currentAttributes.damage) - distanceToEnemyKingSquared);
            }
            return(rating);
        }
 /// <summary>
 /// Shows fruiton suggestion on the square.
 /// </summary>
 /// <param name="fruiton">fruiton to show suggestion of</param>
 public void SuggestFruiton(Fruiton fruiton)
 {
     IsSuggestionShown = true;
     spineSkeleton.gameObject.SetActive(true);
     spineSkeleton.Skeleton.SetSkin(fruiton.model);
     spineSkeleton.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
 }
 /// <summary>
 /// Sets a fruiton to the square.
 /// </summary>
 /// <param name="fruiton">fruiton to set</param>
 public void SetFruiton(Fruiton fruiton)
 {
     IsEmpty       = false;
     KernelFruiton = fruiton;
     spineSkeleton.gameObject.SetActive(true);
     spineSkeleton.Skeleton.SetSkin(fruiton.model);
     spineSkeleton.color = Color.white;
 }
Exemple #4
0
        private bool IsBetterMove(MoveAction newAction, float currentDistance, MoveAction prevAction, float bestDistance, Kernel kernel)
        {
            var     newContext  = (MoveActionContext)newAction.getContext();
            var     prevContext = (MoveActionContext)prevAction.getContext();
            Fruiton newSource   = KernelUtils.GetFruitonAt(kernel, newContext.source);
            Fruiton prevSource  = KernelUtils.GetFruitonAt(kernel, prevContext.source);

            float newDistModifier  = newSource.type == Fruiton.MAJOR_TYPE ? -1 : newSource.get_isKing() ? +1 : 0;
            float prevDistModifier = prevSource.type == Fruiton.MAJOR_TYPE ? -1 : prevSource.get_isKing() ? +1 : 0;

            return(currentDistance + newDistModifier < bestDistance + prevDistModifier);
        }
        public static GameObject CreateClientFruiton(int id, GameObject parent)
        {
            FruitonDatabase fruitonDatabase  = GameManager.Instance.FruitonDatabase;
            Fruiton         kernelFruiton    = FruitonFactory.makeFruiton(id, fruitonDatabase);
            var             newFruitonObject = UnityEngine.Object.Instantiate(Resources.Load("Models/Battle/BoyFighter", typeof(GameObject))) as GameObject;

            newFruitonObject.GetComponentInChildren <SkeletonAnimation>().skeleton.SetSkin(kernelFruiton.model);
            newFruitonObject.AddComponent <ClientFruiton>().KernelFruiton = kernelFruiton;
            newFruitonObject.transform.parent = parent.transform;

            return(newFruitonObject);
        }
        /// <summary>
        /// Load fruiton data to display in the window.
        /// </summary>
        /// <param name="fruiton">fruiton to load</param>
        /// <param name="isFreeSquareInTeam">true if given fruiton can be added to the team</param>
        public void SetFruiton(FridgeFruiton fruiton, bool isFreeSquareInTeam)
        {
            var kFruiton = fruiton.KernelFruiton;

            CurrentFruiton = kFruiton;

            if (typeIconSprites == null)
            {
                LoadIconSprites();
            }

            TypeImage.sprite = typeIconSprites[kFruiton.type];
            Color color;

            ColorUtility.TryParseHtmlString(FridgeFruiton.TypeColors[kFruiton.type] + "55", out color);
            TypeImage.color = color;
            ColorUtility.TryParseHtmlString(FridgeFruiton.TypeColors[kFruiton.type] + "88", out color);
            TypeText.color = color;
            TypeText.text  = ((FruitonType)FruitonType.ToObject(typeof(FruitonType), kFruiton.type)).ToString();
            NameText.text  = kFruiton.model;

            AddToTeamButton.gameObject.SetActive(fruiton.IsOwned && isFreeSquareInTeam && fruiton.Count > 0);

            if (!fruiton.IsOwned)
            {
                TipText.text  = TIP_FRUITON_NOT_OWNED;
                TipText.color = ERROR_TIP_COLOR;
                return;
            }

            if (fruiton.Count == 0)
            {
                TipText.text  = String.Format(TIP_FRUITON_ALREADY_USED, fruiton.KernelFruiton.name);
                TipText.color = ERROR_TIP_COLOR;
                return;
            }

            if (isFreeSquareInTeam)
            {
#if UNITY_ANDROID
                TipText.text  = TIP_ANDROID_DND;
                TipText.color = Color.black;
#else
                TipText.text = "";
#endif
            }
            else
            {
                TipText.text  = TIP_FRUITON_NO_SQUARES_LEFT;
                TipText.color = ERROR_TIP_COLOR;
            }
        }
Exemple #7
0
        private bool IsBetterHeal(HealAction newAction, HealAction prevAction, Kernel kernel)
        {
            var     newContext  = (HealActionContext)newAction.getContext();
            var     prevContext = (HealActionContext)prevAction.getContext();
            Fruiton newTarget   = KernelUtils.GetFruitonAt(kernel, newContext.target);
            Fruiton prevTarget  = KernelUtils.GetFruitonAt(kernel, prevContext.target);

            int newHealAmount  = Math.Min(newContext.heal, newTarget.originalAttributes.hp - newTarget.currentAttributes.hp);
            int prevHealAmount = Math.Min(prevContext.heal, prevTarget.originalAttributes.hp - prevTarget.currentAttributes.hp);

            return(newTarget.get_isKing() ||
                   newTarget.type == Fruiton.MAJOR_TYPE && prevTarget.type == Fruiton.MINOR_TYPE ||
                   newTarget.type == prevTarget.type && newHealAmount > prevHealAmount);
        }
Exemple #8
0
        /// <summary>
        /// Loads data from kernel fruiton and displays them on the game object.
        /// </summary>
        /// <param name="kFruiton">kernel fruiton to load</param>
        public void SetKernelFruiton(Fruiton kFruiton)
        {
            KernelFruiton   = kFruiton;
            TextAttack.text = kFruiton.currentAttributes.damage.ToString();
            TextHealth.text = kFruiton.currentAttributes.hp.ToString();
            Count           = GameManager.Instance.AvailableFruitons.Count(id => id == kFruiton.dbId);
            textName.text   = kFruiton.name;
            Color color;

            ColorUtility.TryParseHtmlString(TypeColors[kFruiton.type], out color);
            PanelName.color = color;
            foreach (var icon in TypeIcons)
            {
                icon.sprite = typeIconSprites[kFruiton.type];
            }
            SpineSkeleton.Skeleton.SetSkin(kFruiton.model);
        }
Exemple #9
0
        private bool IsBetterAttack(AttackAction newAction, AttackAction prevAction, Kernel kernel)
        {
            var     newContext  = (AttackActionContext)newAction.getContext();
            var     prevContext = (AttackActionContext)prevAction.getContext();
            Fruiton newTarget   = KernelUtils.GetFruitonAt(kernel, newContext.target);
            Fruiton prevTarget  = KernelUtils.GetFruitonAt(kernel, prevContext.target);

            bool isNewKill  = newTarget.currentAttributes.hp <= newContext.damage;
            bool isPrevKill = prevTarget.currentAttributes.hp <= prevContext.damage;

            if (prevTarget.get_isKing())
            {
                return(false);
            }

            return(newTarget.get_isKing() ||
                   isNewKill && !isPrevKill ||
                   newContext.damage > prevContext.damage ||
                   newTarget.type == Fruiton.MAJOR_TYPE && prevTarget.type == Fruiton.MINOR_TYPE);
        }
Exemple #10
0
        public static string GenerateTooltip(Fruiton kernelFruiton)
        {
            var fruitonInfo = new StringBuilder("<b>" + kernelFruiton.name.ToUpper() + "</b>\n");

            fruitonInfo.Append("<b>Movement range: </b>");
            foreach (MoveGenerator moveGenerator in kernelFruiton.moveGenerators.ToList())
            {
                fruitonInfo.Append(moveGenerator);
            }

            fruitonInfo.Append("\n<b>Attack range: </b>");
            foreach (AttackGenerator attackGenerator in kernelFruiton.attackGenerators.ToList())
            {
                fruitonInfo.Append(attackGenerator);
            }

            List <object> abilities = kernelFruiton.abilities.ToList();

            if (abilities.Count > 0)
            {
                fruitonInfo.Append("\n<b>Abilities</b>\n");
                foreach (Ability ability in abilities)
                {
                    fruitonInfo.Append(string.Format(ability.text, kernelFruiton.currentAttributes.heal));
                }
            }

            List <object> effects    = kernelFruiton.effects.ToList();
            int           decayCount = 0;

            if (effects.Count > 0)
            {
                fruitonInfo.Append("\n<b>Effects</b>\n");
                foreach (Effect effect in effects)
                {
                    if (effect.GetType() == typeof(DecayEffect))
                    {
                        decayCount++;
                    }
                    else
                    {
                        fruitonInfo.Append(effect.getDescription()).Append("\n");
                    }
                }
                if (decayCount > 0)
                {
                    fruitonInfo.Append("Decay");
                    if (decayCount > 1)
                    {
                        fruitonInfo.Append(" (").Append(decayCount).Append("x)");
                    }
                    fruitonInfo.Append("\n");
                }
            }

            foreach (int immunity in kernelFruiton.currentAttributes.immunities.ToList())
            {
                if (immunity == HealAction.ID)
                {
                    fruitonInfo.Append("Can't be healed.\n");
                }
                else if (immunity == AttackAction.ID)
                {
                    fruitonInfo.Append("Can't be attacked.\n");
                }
            }

            return(fruitonInfo.ToString());
        }