public override void DoAction(IEventArgs args)
        {
            ParaList target = GetTarget(args);
            object   source = GetSource(args);

            if (fields != null && source != null && target != null)
            {
                foreach (FieldPair fN in FieldPair.Parse(fields))
                {
                    string[] ffs = new string[2];
                    ffs[0] = fN.GetFrom();
                    ffs[1] = fN.GetTo();
                    try
                    {
                        FieldInfo    f    = ReflectionCache.GetField(source, ffs[0].Trim());
                        AbstractPara para = null;
                        string       type = f.GetType().Name.ToLower();
                        if ("long".Equals(type))
                        {
                            para = new LongPara(ffs[1].Trim());
                        }
                        if ("int".Equals(type))
                        {
                            para = new IntPara(ffs[1].Trim());
                        }
                        if ("float".Equals(type))
                        {
                            para = new FloatPara(ffs[1].Trim());
                        }
                        if ("double".Equals(type))
                        {
                            para = new DoublePara(ffs[1].Trim());
                        }
                        if ("string".Equals(type))
                        {
                            para = new StringPara(ffs[1].Trim());
                        }
                        if ("boolean".Equals(type))
                        {
                            para = new BoolPara(ffs[1].Trim());
                        }
                        if (para == null)
                        {
                            throw new GameConfigExpception(ffs[1].Trim() + "'s type '" + type + "' is not supported.");
                        }

                        para.SetValue(f.GetValue(source));

                        target.AddPara(para);
                    }
                    catch (Exception e)
                    {
                        throw new GameConfigExpception(fN + " is not a valid field.\n" + ExceptionUtil.GetExceptionContent(e));
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static IPara GetPara(object obj, string field)
        {
            if (obj == null)
            {
                return(null);
            }
            FieldInfo    f    = GetField(obj, field);
            AbstractPara para = null;

            if (f != null)
            {
                string type = f.FieldType.Name;

                if (ParseUtility.IsInt64(type))
                {
                    para = new LongPara(field);
                }
                if (ParseUtility.IsInt32(type))
                {
                    para = new IntPara(field);
                }
                if (ParseUtility.IsSingle(type))
                {
                    para = new FloatPara(field);
                }
                if (ParseUtility.IsDouble(type))
                {
                    para = new DoublePara(field);
                }
                if (ParseUtility.IsString(type))
                {
                    para = new StringPara(field);
                }
                if (ParseUtility.IsBoolean(type))
                {
                    para = new BoolPara(field);
                }
                try
                {
                    if (para != null)
                    {
                        para.SetValue(f.GetValue(obj));
                    }
                }
                catch (Exception e)
                {
                    throw new GameConfigExpception(field + " is not a valid field.\n" + ExceptionUtil.GetExceptionContent(e));
                }
            }
            return(para);
        }
Ejemplo n.º 3
0
        public static IPara GetPara(object obj, string field)
        {
            if (obj == null)
            {
                return(null);
            }
            FieldInfo    f    = GetField(obj, field);
            AbstractPara para = null;

            if (f != null)
            {
                string type = f.FieldType.Name.ToLower();
                if ("int64".Equals(type))
                {
                    para = new LongPara(field);
                }
                if ("int32".Equals(type))
                {
                    para = new IntPara(field);
                }
                if ("single".Equals(type))
                {
                    para = new FloatPara(field);
                }
                if ("double".Equals(type))
                {
                    para = new DoublePara(field);
                }
                if ("string".Equals(type))
                {
                    para = new StringPara(field);
                }
                if ("boolean".Equals(type))
                {
                    para = new BoolPara(field);
                }
                try
                {
                    if (para != null)
                    {
                        para.SetValue(f.GetValue(obj));
                    }
                }
                catch (Exception e)
                {
                    throw new GameConfigExpception(field + " is not a valid field.\n" + ExceptionUtil.GetExceptionContent(e));
                }
            }
            return(para);
        }
Ejemplo n.º 4
0
        public override void DoAction(IEventArgs args)
        {
            UnitPosition up = pos.Select(args);

            float       realRadius = FreeUtil.ReplaceFloat(radius, args);
            float       realDamage = FreeUtil.ReplaceFloat(damage, args);
            EUIDeadType realType   = (EUIDeadType)FreeUtil.ReplaceInt(type, args);

            if (damagePara == null)
            {
                damagePara = new FloatPara("damage", realDamage);
                disPara    = new FloatPara("dis", 0f);
                typePara   = new StringPara("type", FreeUtil.ReplaceVar(type, args));
            }

            if (up != null)
            {
                var bombPos   = new Vector3(up.GetX(), up.GetY(), up.GetZ());
                var colliders = Physics.OverlapSphere(bombPos, realRadius,
                                                      UnityLayerManager.GetLayerMask(EUnityLayerName.Player) | UnityLayerManager.GetLayerMask(EUnityLayerName.UserInputRaycast)
                                                      | UnityLayerManager.GetLayerMask(EUnityLayerName.Vehicle) | UnityLayerManager.GetLayerMask(EUnityLayerName.Glass));

                foreach (var collider in colliders)
                {
                    float trueDamage = CalculateBombDamage(collider.transform, bombPos, realDamage, realType);

                    if (Logger.IsDebugEnabled)
                    {
                        Logger.DebugFormat("Process {0}", collider.name);
                    }
                    if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.Player))
                    {
                        HandlePlayer(collider, args, args.GameContext, trueDamage, bombPos);
                    }
                    if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.UserInputRaycast))
                    {
                        HandleFracturedObjects(collider.transform, bombPos, trueDamage);
                    }
                    if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.Vehicle))
                    {
                        HandleVehicle(collider.transform, trueDamage);
                    }
                    if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.Glass))
                    {
                        HandleGlass(collider.transform);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 private void HandleArmor(IEventArgs args)
 {
     if ("ReduceDamage" == code)
     {
         FreeData fd = (FreeData)args.GetUnit("target");
         if (fd != null)
         {
             SimpleParable sp = (SimpleParable)args.GetUnit("damage");
             if (sp != null)
             {
                 PlayerDamageInfo info = (PlayerDamageInfo)((ObjectFields)((SimpleParaList)sp.GetParameters()).GetFieldList()[0]).GetObj();
                 float            da   = ReduceDamageUtil.HandleDamage(args, fd, info);
                 FloatPara        d    = (FloatPara)args.GetDefault().GetParameters().Get("damage");
                 if (d != null)
                 {
                     d.SetValue(da);
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
        public float HandleDamage(PlayerEntity source, PlayerEntity target, PlayerDamageInfo damage)
        {
            if (damagePara == null)
            {
                damagePara = new FloatPara("damage", damage.damage);
            }

            damagePara.SetValue(Math.Min(damage.damage, target.gamePlay.CurModeHp));

            if (!this.args.Triggers.IsEmpty(FreeTriggerConstant.DAMAGE))
            {
                if (source != null)
                {
                    args.TempUse("source", (FreeData)source.freeData.FreeData);
                }
                args.TempUse("target", (FreeData)target.freeData.FreeData);

                SimpleParaList dama = new SimpleParaList();
                dama.AddFields(new ObjectFields(damage));
                SimpleParable sp = new SimpleParable(dama);
                args.TempUse("damage", sp);

                args.TempUsePara(damagePara);

                this.args.Triggers.Trigger(FreeTriggerConstant.DAMAGE, args);

                if (source != null)
                {
                    args.Resume("source");
                }

                args.Resume("target");
                args.Resume("damage");
                args.ResumePara("damage");
            }


            return((float)damagePara.GetValue());
        }
Ejemplo n.º 7
0
        private void ReduceDamage(IEventArgs args, PlayerEntity player)
        {
            SimpleParable sp = (SimpleParable)args.GetUnit("damage");

            if (sp != null)
            {
                PlayerDamageInfo damage = (PlayerDamageInfo)sp.GetFieldObject(0);
                float            da     = damage.damage;
                if (damage.part == (int)EBodyPart.Head)
                {
                    int helId = player.gamePlay.HelmetLv;
                    if (armorDic.ContainsKey(helId))
                    {
                        ArmorData ad = armorDic[helId];

                        da = ReduceDamage(args, player, damage, ad.reduce, false);
                    }
                }
                else if (damage.part == (int)EBodyPart.Chest || damage.part == (int)EBodyPart.Stomach || damage.part == (int)EBodyPart.Pelvis)
                {
                    int armor = player.gamePlay.ArmorLv;
                    if (armorDic.ContainsKey(armor))
                    {
                        ArmorData ad = armorDic[armor];

                        da = ReduceDamage(args, player, damage, ad.reduce, true);
                    }
                }

                FloatPara d = (FloatPara)args.GetDefault().GetParameters().Get("damage");
                if (d != null)
                {
                    d.SetValue(da);
                }
            }
        }
Ejemplo n.º 8
0
        public override void DoAction(IEventArgs args)
        {
            PlayerEntity playerEntity = GetPlayerEntity(args);

            if (playerEntity != null)
            {
                SimpleParable sp = (SimpleParable)args.GetUnit("damage");
                if (sp != null)
                {
                    FloatPara        d      = (FloatPara)args.GetDefault().GetParameters().Get("damage");
                    PlayerDamageInfo damage = (PlayerDamageInfo)sp.GetFieldObject(0);

                    if (damage.type != (int)EUIDeadType.Weapon && damage.type != (int)EUIDeadType.Unarmed)
                    {
                        return;
                    }

                    if (playerEntity.gamePlay.CurHelmet > 0)
                    {
                        var config = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(playerEntity.gamePlay.HelmetLv);
                        if (config != null)
                        {
                            if (config.NewWeaponCfg.ProtectivePartsList.Contains(damage.part))
                            {
                                float readDamage = damage.damage;
                                float reduce     = readDamage * config.NewWeaponCfg.DamageReduction / 100;
                                reduce = Math.Min(playerEntity.gamePlay.CurHelmet, reduce);
                                playerEntity.gamePlay.CurHelmet = Math.Max(0, playerEntity.gamePlay.CurHelmet - (int)readDamage);
                                if (reduce > 0 && playerEntity.gamePlay.CurHelmet == 0)
                                {
                                    playerEntity.gamePlay.HelmetLv = playerEntity.gamePlay.MaxHelmet = 0;
                                    SimpleProto msg = FreePool.Allocate();
                                    msg.Key = FreeMessageConstant.ChickenTip;
                                    msg.Ss.Add("word75," + config.NewWeaponCfg.Name);
                                    FreeMessageSender.SendMessage(playerEntity, msg);
                                }

                                damage.damage -= reduce;
                                playerEntity.statisticsData.Statistics.DefenseDamage += reduce;

                                d.SetValue(damage.damage);
                            }
                        }
                    }

                    if (playerEntity.gamePlay.CurArmor > 0)
                    {
                        var config = SingletonManager.Get <WeaponConfigManagement>().FindConfigById(playerEntity.gamePlay.ArmorLv);
                        if (config != null)
                        {
                            if (config.NewWeaponCfg.ProtectivePartsList.Contains(damage.part))
                            {
                                float readDamage = damage.damage;
                                float reduce     = readDamage * config.NewWeaponCfg.DamageReduction / 100;
                                reduce = Math.Min(playerEntity.gamePlay.CurArmor, reduce);
                                playerEntity.gamePlay.CurArmor = Math.Max(0, playerEntity.gamePlay.CurArmor - (int)readDamage);
                                if (reduce > 0 && playerEntity.gamePlay.CurArmor == 0)
                                {
                                    playerEntity.gamePlay.ArmorLv = playerEntity.gamePlay.MaxArmor = 0;
                                    SimpleProto msg = FreePool.Allocate();
                                    msg.Key = FreeMessageConstant.ChickenTip;
                                    msg.Ss.Add("word75," + config.NewWeaponCfg.Name);
                                    FreeMessageSender.SendMessage(playerEntity, msg);
                                }

                                damage.damage -= reduce;
                                playerEntity.statisticsData.Statistics.DefenseDamage += reduce;

                                d.SetValue(damage.damage);
                            }
                        }
                    }
                }
            }
        }