예제 #1
0
        public static float CalculateTotal(RangeStat stat, float percent)
        {
            LastQueryString.Clear();
            LastQueryString.Append("Base ");
            LastQueryString.Append(stat.Label);
            LastQueryString.Append(": ");
            LastQueryString.Append(stat.BaseValue.ToString("F0"));
            LastQueryString.Append("-");
            LastQueryString.Append((stat.BaseValue + stat.MaxModifier).ToString("F0"));
            LastQueryString.Append(" + ");
            LastQueryString.AppendNewLine(stat.ModTotal.ToString("F0"));
            var roll = Game.Random.NextFloat(stat.BaseValue, stat.BaseValue + stat.MaxModifier);

            LastQueryString.Append("Rolled ");
            LastQueryString.Append(roll.ToString("F0"));
            LastQueryString.Append(" + ");
            LastQueryString.Append(stat.ModTotal.ToString("F0"));
            LastQueryString.Append(" = ");
            var result = roll + stat.ModTotal;

            LastQueryString.Append(result.ToString("F0"));
            if (Math.Abs(percent - 1) > 0.0001f)
            {
                LastQueryString.Append(" * ");
                LastQueryString.Append(percent.ToString("F1"));
                LastQueryString.Append(" Final: ");
                result *= percent;
                LastQueryString.Append(result.ToString("F0"));
            }
            return(result);
        }
예제 #2
0
 public static void AddStatList(Entity entity, DataList stats, Equipment equipment)
 {
     if (stats == null)
     {
         return;
     }
     for (int i = 0; i < stats.Count; i++)
     {
         var statEntry = stats[i];
         var statName  = statEntry.GetValue <string>(DatabaseFields.Stat);
         if (string.IsNullOrEmpty(statName))
         {
             continue;
         }
         var label      = statEntry.TryGetValue("Label", statName);
         var amount     = statEntry.GetValue <int>(DatabaseFields.Amount);
         var multiplier = statEntry.GetValue <float>(DatabaseFields.Multiplier);
         var addToEquip = statEntry.GetValue <bool>(DatabaseFields.AddToEquipList);
         if (equipment != null && addToEquip)
         {
             equipment.AddStat(statName);
         }
         if (Math.Abs(multiplier) < Comparison || Math.Abs(multiplier - 1) < Comparison)
         {
             entity.Stats.GetOrAdd(statName, label).AddToBase(amount);
             continue;
         }
         var    stat = entity.Stats.Get(statName);
         string id   = "";
         label = "";
         float     adjustedAmount = amount;
         RangeStat rangeStat;
         if (stat != null)
         {
             adjustedAmount = stat.BaseValue + amount;
             rangeStat      = stat as RangeStat;
             if (rangeStat != null)
             {
                 rangeStat.SetValue(adjustedAmount, adjustedAmount * multiplier);
                 continue;
             }
             id    = stat.ID;
             label = stat.Label;
             entity.Stats.Remove(stat);
         }
         if (string.IsNullOrEmpty(id))
         {
             var fakeEnum = GameData.Enums.GetEnumIndex(statName, out var index);
             if (fakeEnum != null)
             {
                 id    = fakeEnum.GetID(index);
                 label = fakeEnum.GetNameAt(index);
             }
             else
             {
                 id = label = statName;
             }
         }
         rangeStat = new RangeStat(label, id, adjustedAmount, adjustedAmount * multiplier);
         entity.Stats.Add(rangeStat);
     }
 }
예제 #3
0
        public void AddComponent(Entity entity, DataEntry data)
        {
            var action = entity.Add(new ActionConfig());

            var type  = data.Get <DataReference>(DatabaseFields.ItemType);
            var skill = data.TryGetValue <string>(DatabaseFields.Skill, "");

            action.Primary     = type?.TargetID == "WeaponUsable";
            action.WeaponModel = data.TryGetValue("WeaponModel", "");
            if (!string.IsNullOrEmpty(action.WeaponModel))
            {
                entity.Add(new WeaponModelComponent(action.WeaponModel));
            }
            else
            {
                action.WeaponModel = data.TryGetValue("SpriteWeaponModel", "");
            }
            var stats = entity.Get <StatsContainer>();
            var power = new RangeStat(entity, Stats.Power, Stats.Power, data.TryGetValue(DatabaseFields.PowerMin, 0f), data.TryGetValue
                                          (DatabaseFields.PowerMax, 1f));

            stats.Add(power);
            bool generateCollision = false;
            var  targeting         = ParseUtilities.TryParseEnum(data.TryGetValue("TargetType", "Enemy"), TargetType.Enemy);

            if (targeting == TargetType.Self || targeting == TargetType.Friendly)
            {
                generateCollision = true;
            }
            bool limitEnemy  = true;
            var  config      = data.Get <DataList>("Config");
            var  abilityType = data.TryGetValue("Type", "Attack");
            var  damageType  = data.TryGetValue(DatabaseFields.DamageType,
                                                GameData.DamageTypes.GetID(0));

            if (type != null && type.TargetID == "Ability")
            {
                action.AnimationTrigger = data.TryGetValue("Animation", GraphTriggers.UseAbility);
                action.EquipVariable    = "";
                var secondaryType = data.TryGetValue("SecondaryType", "");
                switch (abilityType)
                {
                default:
                case "Attack":
                    entity.Add(
                        new DamageImpact(damageType, Stats.Health, 1));
                    break;

                case "Heal":
                    entity.Add(AddHealImpact(config, false));
                    generateCollision = true;
                    limitEnemy        = false;
                    break;

                case "AddModImpact":
                    entity.Add(AddModImpact(entity, config));
                    generateCollision = true;
                    limitEnemy        = false;
                    break;

                case "Teleport":
                case "Shield":
                case "Unlock":
                    break;
                }
                switch (secondaryType)
                {
                case "Heal":
                    entity.Add(AddHealImpact(config, true));
                    break;

                case "AddModImpact":
                    entity.Add(AddModImpact(entity, config));
                    break;

                case "ConvertVital":
                    entity.Add(new ConvertVitalImpact(config.FindFloat("Percent", 1f), config.FindString("SourceVital"), config.FindString("TargetVital")));
                    break;

                case "InstantKill":
                    entity.Add(new InstantKillImpact(config.FindFloat("Chance", 1f)));
                    break;

                case "Confuse":
                    entity.Add(
                        new ApplyTagImpact(EntityTags.IsConfused, data.TryGetValue("SecondaryPower", EffectChance), config
                                           .FindFloat("Length", EffectTime), damageType, "Confusion"));
                    break;

                case "Slow":
                    entity.Add(new ApplyTagImpact(EntityTags.IsSlowed, data.TryGetValue("SecondaryPower", EffectChance), config
                                                  .FindFloat("Length", EffectTime), damageType, "Slow"));
                    break;

                case "Stun":
                    entity.Add(new ApplyTagImpact(EntityTags.IsStunned, data.TryGetValue("SecondaryPower", EffectChance), config
                                                  .FindFloat("Length", EffectTime), damageType, "Stun"));
                    break;
                }
                switch (abilityType)
                {
                default:
                    action.Costs.Add(new CostVital(Stats.Energy, data.TryGetValue("Cost", 1f), skill));
                    break;

                case "Shield":
                case "Unlock":
                    break;
                }
            }
            else
            {
                action.AnimationTrigger = GraphTriggers.Attack;
                action.EquipVariable    = data.TryGetValue("EquipVariable", "");
                entity.Add(
                    new DamageImpact(data.TryGetValue(DatabaseFields.DamageType,
                                                      GameData.DamageTypes.GetID(0)), Stats.Health, 1));
                var           reload      = data.TryGetValue("ReloadType", "Repair");
                var           reloadSpeed = data.TryGetValue("ReloadSpeed", 1f);
                var           ammo        = AmmoFactory.GetTemplate(data.Get <DataReference>("Ammo"));
                AmmoComponent ammoComponent;
                switch (reload)
                {
                case "Repair":
                    ammoComponent = entity.Add(new AmmoComponent(ammo, skill, reloadSpeed, power, _brokenWeaponPercent));
                    var handlers = entity.GetOrAdd <RuleEventListenerComponent>();
                    handlers.Handlers.Add(World.Get <AmmoSystem>());
                    break;

                default:
                case "Reload":
                    ammoComponent = entity.Add(new AmmoComponent(ammo, skill, reloadSpeed, null));
                    action.Costs.Add(new CostAmmo(ammoComponent));
                    break;
                }
                ammoComponent.Amount.SetLimits(0, data.TryGetValue("AmmoAmount", 5));
                ammoComponent.Amount.SetMax();
            }
            switch (abilityType)
            {
            default:
                var radius = ParseUtilities.TryParseEnum(data.TryGetValue(DatabaseFields.Radius, "Single"), ImpactRadiusTypes.Single);
                if (radius != ImpactRadiusTypes.Single)
                {
                    entity.Add(new ImpactRadius(radius, true));
                }
                action.Range = GameData.ActionDistance.GetAssociatedValue(data.TryGetValue("Range", "Medium"));
                var spawn = data.Get <DataReference>(DatabaseFields.ActionSpawn);
                if (spawn != null)
                {
                    action.AddEvent(AnimationEvents.Default, new EventSpawnProjectile(spawn.TargetID));
                }
                else
                {
                    if (generateCollision)
                    {
                        action.AddEvent(AnimationEvents.Default, new EventGenerateCollisionEvent());
                    }
                    else
                    {
                        var collisionType = data.TryGetValue("CollisionType", "Point");
                        var raycastSize   = GameData.CollisionType.GetAssociatedValue(collisionType) * 0.01f;
                        switch (collisionType)
                        {
                        case "Melee":
                        case "MeleeBig":
                            action.AddEvent(AnimationEvents.CollisionOrImpact, new CameraShakeEvent(new Vector3
                                                                                                        (0, 0, 1), 4, false));
                            break;
                        }
                        //melee or hitscan need to make that clearer
                        action.AddEvent(AnimationEvents.Default, new EventCheckRaycastCollision(action.Range, raycastSize, limitEnemy));
                    }
                }
                break;

            case "Shield":
                entity.Add(
                    new BlockDamageAction(
                        config.FindString("Model", "Shield"), "Vitals.Energy",
                        data.TryGetValue("Cost", 1f), skill, PlayerControls.UseSecondary));
                break;
                //case "Teleport":
                //    sequence.Add(new PlayActionAnimation(ActionStateEvents.None, animation, true, false, true));
                //    sequence.Add(new WaitForAnimation(ActionStateEvents.Activate, animation, true, _defaultAnimationTimeout));
                //    sequence.Add(new TeleportSequence(ActionStateEvents.None, config.FindInt("Distance", 5)));
                //    break;
                //case "Unlock":
                //    sequence.Add(new PlayActionAnimation(ActionStateEvents.None, animation, true, false, true));
                //    sequence.Add(new WaitForAnimation(ActionStateEvents.Activate, animation, true, _defaultAnimationTimeout));
                //    sequence.Add(new Unlock(ActionStateEvents.None, power.UpperRange, data.TryGetValue("Cost", 1f)));
                //    break;
            }
            var afx = data.GetValue <string>(DatabaseFields.ActionFx);

            if (!string.IsNullOrEmpty(afx))
            {
                var actionFx = ItemPool.LoadAsset <ActionFx>(UnityDirs.ActionFx, afx);
                if (actionFx != null)
                {
                    if (actionFx.TryGetColor(out var actionColor))
                    {
                        entity.Add(new HitParticlesComponent(actionColor));
                    }
                    entity.Add(new ActionFxComponent(actionFx));
                }
            }
            var customScripting = data.Get <DataList>("ScriptedEvents");

            if (customScripting != null)
            {
                for (int i = 0; i < customScripting.Count; i++)
                {
                    var scriptingData = customScripting[i];
                    var eventType     = scriptingData.TryGetValue("Event", "");
                    //var eventType = ParseUtilities.TryParseEnum(scriptingData.TryGetValue("Event", ""), ActionState.None);
                    var scripting = scriptingData.TryGetValue("Script", "");
                    if (!string.IsNullOrEmpty(eventType) && !string.IsNullOrEmpty(scripting))
                    {
                        var customScript = ScriptingSystem.ParseMessage(scripting.SplitIntoWords());
                        if (customScript != null)
                        {
                            action.AddEvent(eventType, customScript);
                        }
                    }
                }
            }
        }