Example #1
0
        public static DamageResult GetDamageResult(int damage, DamageType dType, BattleCharacter defencer)
        {
            bool isMissed = false;

            switch (dType)
            {
            case DamageType.Physical:
            {
                var d = defencer[HeroPropertyType.Defance].FinalValue + defencer[HeroPropertyType.Agility].FinalValue * AGILITY_DEFANCE;
                //处理防御((装甲)*0.006))/(1+0.006*(装甲)
                damage = damage - (int)(damage *
                                        (d * DEFANCE_RATE) / (1 + DEFANCE_RATE * d));

                isMissed = GRandomer.Probability10000(defencer[HeroPropertyType.Jouk].FinalValue);
            }
            break;

            case DamageType.Magic:
            {
                damage = (int)(damage * (1 - defencer[HeroPropertyType.Resistibility].FinalValue / 10000f));
            }
            break;

            default:
                break;
            }

            return(new DamageResult
            {
                Damage = damage,
                DType = dType,
                IsMissed = isMissed
            });
        }
        //处理掉落
        private void DoDrop()
        {
            if (drop == null)
            {
                return;
            }
            var items = drop.DropItem.SplitToInt();
            var pors  = drop.Pro.SplitToInt();

            foreach (var i in this.BattlePlayers)
            {
                var notify = new Notify_Drop();
                notify.UserID = i.Value.User.UserID;
                var gold = GRandomer.RandomMinAndMax(drop.GoldMin, drop.GoldMax);
                notify.Gold = gold;
                i.Value.AddGold(gold);
                if (items.Count > 0)
                {
                    for (var index = 0; index < items.Count; index++)
                    {
                        if (GRandomer.Probability10000(pors[index]))
                        {
                            i.Value.AddDrop(items[index], 1);
                            notify.Items.Add(new PlayerItem {
                                ItemID = items[index], Num = 1
                            });
                        }
                    }
                }
                Client client;
                if (this.Clients.TryToGetValue(i.Value.User.UserID, out client))
                {
                    var message = NetProtoTool.ToNetMessage(MessageClass.Notify, notify);
                    client.SendMessage(message);
                }
            }
        }
        public override G2C_EquipmentLevelUp DoResponse(C2G_EquipmentLevelUp request, Client client)
        {
            var      userID = (long)client.UserState;
            UserData userData;

            if (!MonitorPool.S.Get <UserDataManager>().TryToGetUserData(userID, out userData))
            {
                return(new G2C_EquipmentLevelUp {
                    Code = ErrorCode.NoGamePlayerData
                });
            }

            var item = userData.GetItemByGuid(request.Guid);

            if (item == null)
            {
                return new G2C_EquipmentLevelUp {
                           Code = ErrorCode.NOFoundItem
                }
            }
            ;
            var itemconfig = ExcelToJSONConfigManager.Current.GetConfigByID <ItemData>(item.ItemID);

            if ((ItemType)itemconfig.ItemType != ItemType.Equip)
            {
                return new G2C_EquipmentLevelUp {
                           Code = ErrorCode.Error
                }
            }
            ;
            //装备获取失败
            var equipconfig = ExcelToJSONConfigManager
                              .Current.GetConfigByID <EquipmentData>(int.Parse(itemconfig.Params1));

            if (equipconfig == null)
            {
                return new G2C_EquipmentLevelUp {
                           Code = ErrorCode.Error
                }
            }
            ;

            var equip = userData.GetEquipByGuid(request.Guid);

            if (equip == null)
            {
                if (!userData.MakeEquipInit(request.Guid))
                {
                    return(new G2C_EquipmentLevelUp {
                        Code = ErrorCode.Error
                    });                                                        //nofound item?
                }
                else
                {
                    equip = userData.GetEquipByGuid(request.Guid);
                }
            }

            if (equip == null)
            {
                return(new G2C_EquipmentLevelUp {
                    Code = ErrorCode.Error
                });
            }

            //等级不一样
            if (equip.Level != request.Level)
            {
                return(new G2C_EquipmentLevelUp
                {
                    Code = ErrorCode.Error
                });
            }

            var levelconfig = ExcelToJSONConfigManager
                              .Current
                              .FirstConfig <EquipmentLevelUpData>(t =>
            {
                return(t.Level == request.Level + 1 && t.Quility == equipconfig.Quility);
            });

            if (levelconfig == null)
            {
                //max level
                return(new G2C_EquipmentLevelUp {
                    Code = ErrorCode.Error
                });
            }

            if (levelconfig.CostGold > userData.Gold || levelconfig.CostCoin > userData.Coin)
            {
                return(new G2C_EquipmentLevelUp {
                    Code = ErrorCode.NoEnoughtGold
                });
            }


            if (levelconfig.CostGold > 0)
            {
                userData.SubGold(levelconfig.CostGold);
            }
            if (levelconfig.CostCoin > 0)
            {
                userData.SubCoin(levelconfig.CostCoin);
            }

            var levelUp = GRandomer.Probability10000(levelconfig.Pro);

            if (levelUp)
            {
                userData.LevelUpGuild(request.Guid);
            }

            return(new G2C_EquipmentLevelUp
            {
                Code = ErrorCode.OK,
                LevelUp = levelUp,
                Coin = userData.Coin,
                Gold = userData.Gold,
                ResultEquip = equip
            });
        }
    }
}