Пример #1
0
        public void Initialize(Canvas canvas, int magicId, Action onClicked = null)
        {
            this.transform.parent = canvas.transform;
            this.indicator        = this.transform.Find("SelectionIndicator");
            SetSelected(false);

            // canvas.worldCamera = camera;
            // this.canvas = canvas;

            this.magic = DefinitionStore.Instance.GetMagicDefinition(magicId);
            if (this.magic == null)
            {
                throw new ArgumentException("Cannot find magic definition with ID=" + magicId);
            }

            if (onClicked != null)
            {
                Clickable clickable = indicator.GetComponent <Clickable>();
                clickable.Initialize(onClicked);
            }

            // Name
            string      name = LocalizedStrings.GetMagicName(magicId);
            TextMeshPro text = RenderText(name, "Name", FontAssets.FontSizeType.Normal);

            text.transform.localScale = new Vector3(7, 7, 7);

            // Description
            string      description     = GetMagicDescription(this.magic);
            TextMeshPro descriptionText = RenderText(description, "Description", FontAssets.FontSizeType.Normal);

            descriptionText.transform.localScale = new Vector3(5, 5, 5);
        }
Пример #2
0
        private StateOperationResult OnMagicSelected(int index)
        {
            Debug.Log("MenuActionState: OnMagicSelected.");
            if (index < 0 || index >= this.Creature.Data.Magics.Count)
            {
                // Cancelled
                return(StateOperationResult.Pop());
            }

            int             magicId         = this.Creature.Data.Magics[index];
            MagicDefinition magicDefinition = DefinitionStore.Instance.GetMagicDefinition(magicId);

            if (magicDefinition != null && this.Creature.Data.CanSpellMagic() && magicDefinition.MpCost <= this.Creature.Data.Mp)
            {
                // Enough MP to spell
                SelecteMagicTargetState magicTargetState = new SelecteMagicTargetState(gameAction, this.Creature, magicDefinition);
                return(StateOperationResult.Push(magicTargetState));
            }
            else
            {
                // Go back to open magic info
                CreatureShowInfoPack pack = new CreatureShowInfoPack(this.Creature, CreatureInfoType.SelectMagic);
                SendPack(pack);

                return(StateOperationResult.None());
            }
        }
Пример #3
0
        private void OnSelectedMagic(int magicIndex)
        {
            Debug.Log("OnSelectedMagic: " + magicIndex);

            if (!AllowSelection)
            {
                PickAtIndex(-1);
            }

            int             magicId = creature.Data.Magics[magicIndex];
            MagicDefinition magic   = DefinitionStore.Instance.GetMagicDefinition(magicId);

            if (magicIndex == lastSelectedIndex)
            {
                // Do selected action
                PickAtIndex(magicIndex);
            }

            if (lastSelectedIndex >= 0)
            {
                magicControlls[lastSelectedIndex].SetSelected(false);
            }

            magicControlls[magicIndex].SetSelected(true);
            lastSelectedIndex = magicIndex;
        }
        public SelecteMagicTargetState(IGameAction action, FDCreature creature, MagicDefinition magic) : base(action)
        {
            this.Creature = creature;
            this.Magic    = magic;

            if (this.Creature == null)
            {
                throw new ArgumentNullException("creature");
            }

            if (this.Magic == null)
            {
                throw new ArgumentNullException("magic");
            }
        }
Пример #5
0
        private static AttackInformation MagicFrom(MagicDefinition magic, FDCreature subject, FDCreature target, GameField field)
        {
            bool isHit = FDRandom.BoolFromRate(magic.HittingRate);

            int changedHp = 0;

            if (isHit)
            {
                OccupationDefinition occupation = DefinitionStore.Instance.GetOccupationDefinition(target.Definition.Occupation);
                double hitRate = 1.0f;

                if (occupation != null)
                {
                    hitRate = (100 - occupation.MagicDefendRate) / 100.0f;
                }

                switch (magic.Type)
                {
                case MagicType.Attack:
                    changedHp = -FDRandom.IntFromSpan(magic.Span) + magic.ApInvoledRate * subject.Data.CalculatedAp / 100;
                    changedHp = (int)(changedHp * hitRate);
                    changedHp = Math.Min(0, changedHp);
                    break;

                case MagicType.Recover:
                    changedHp = FDRandom.IntFromSpan(magic.Span);
                    changedHp = Math.Max(0, changedHp);
                    break;

                case MagicType.Offensive:
                    TakeOffensiveEffect(magic, target);
                    break;

                case MagicType.Defensive:
                    TakeDefensiveEffect(magic, target);
                    break;

                default:
                    break;
                }
            }

            AttackInformation info = new AttackInformation(target.Data.Hp, target.Data.Hp + changedHp, false);

            target.Data.UpdateHp(changedHp);

            return(info);
        }
Пример #6
0
        public bool HasAfterMoveMagic()
        {
            if (!HasMagic())
            {
                return(false);
            }

            foreach (int magicId in this.Magics)
            {
                MagicDefinition magic = DefinitionStore.Instance.GetMagicDefinition(magicId);
                if (magic.AllowAfterMove)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #7
0
        void AddMagicsToContainer(GameObject container)
        {
            float zOrder = 2f;

            float intervalX = -8f;
            float intervalY = 1.7f;

            float startX = 9.0f;
            float startY = -2.55f;

            float xOffsetName = -0.5f;
            float xOffsetCost = -4f;

            Vector3 scale = new Vector3(0.35f, 0.35f, 1);

            for (int i = 0; i < creature.Data.Magics.Count; i++)
            {
                int             magicId = creature.Data.Magics[i];
                MagicDefinition magic   = DefinitionStore.Instance.GetMagicDefinition(magicId);

                if (magic == null)
                {
                    continue;
                }

                int x = i / 4;
                int y = i % 4;

                float baseX = startX + intervalX * x;
                float baseY = startY + intervalY * y;

                // Name
                int    val  = i;
                string name = LocalizedStrings.GetMagicName(magicId);
                AddText(name, container.transform, new Vector3(baseX + xOffsetName, zOrder, baseY), scale,
                        () => { this.OnSelectClicked(val); });

                // Cost
                AddText("-MP " + StringUtils.Digit3(magic.MpCost), container.transform, new Vector3(baseX + xOffsetCost, zOrder, baseY), scale);
            }
        }
Пример #8
0
        public static MagicalInformation DealWithMagic(int magicId, FDCreature subject, List <FDCreature> targetList, GameField field)
        {
            MagicalInformation result = new MagicalInformation();

            MagicDefinition magic = DefinitionStore.Instance.GetMagicDefinition(magicId);

            if (magic == null)
            {
                return(null);
            }

            if (subject == null || targetList == null)
            {
                throw new ArgumentNullException("subject or targetList");
            }

            int totalExp = 0;

            foreach (FDCreature target in targetList)
            {
                AttackInformation magicInfo = MagicFrom(magic, subject, target, field);
                result.AddInformation(magicInfo);

                if (magic.Type == MagicType.Attack || magic.Type == MagicType.Recover)
                {
                    totalExp += CalculateAttackExp(subject, target, magicInfo);
                }
                else
                {
                    totalExp += CalculateMagicExp(subject, target, magic);
                }
            }

            if (totalExp > 0)
            {
                // Gain Experience
            }

            return(result);
        }
Пример #9
0
        void OnSelectClicked(int index)
        {
            if (!CanEdit)
            {
                return;
            }

            Debug.Log("Clicked on index: " + index);

            if (showType == ShowType.SelectAllItem)
            {
                OnCallback(index);
            }
            else if (showType == ShowType.SelectEquipItem)
            {
                int            itemId = this.creature.Data.Items[index];
                ItemDefinition item   = DefinitionStore.Instance.GetItemDefinition(itemId);
                if (item.IsEquipment())
                {
                    OnCallback(index);
                }
            }
            else if (showType == ShowType.SelectUseItem)
            {
                int            itemId = this.creature.Data.Items[index];
                ItemDefinition item   = DefinitionStore.Instance.GetItemDefinition(itemId);
                if (item.IsUsable())
                {
                    OnCallback(index);
                }
            }
            else if (showType == ShowType.SelectMagic)
            {
                int             magicId = this.creature.Data.Magics[index];
                MagicDefinition magic   = DefinitionStore.Instance.GetMagicDefinition(magicId);
                OnCallback(index);
            }
        }
Пример #10
0
 protected string GetMagicDescription(MagicDefinition magic)
 {
     return(string.Format(@"-MP{0}", StringUtils.Digit2(magic.MpCost)));
 }
Пример #11
0
 private static void TakeDefensiveEffect(MagicDefinition magic, FDCreature target)
 {
 }
Пример #12
0
 private static int CalculateMagicExp(FDCreature subject, FDCreature target, MagicDefinition magic)
 {
     return(0);
 }