예제 #1
0
    /// <summary>
    /// 更新角色战斗力
    /// </summary>
    /// <param name="roleEntity"></param>
    private void UpdateFighting(RoleEntity roleEntity)
    {
        //1.计算角色基础属性 和等级有关
        //给角色战斗相关的属性赋值
        //职业 等级
        JobEntity jobEntity = JobDBModel.Instance.Get(roleEntity.JobId);

        //职业等级数据
        JobLevelEntity jobLevelEntity = JobLevelDBModel.Instance.Get(roleEntity.Level);

        roleEntity.MaxHP = jobLevelEntity.HP;
        roleEntity.MaxMP = jobLevelEntity.MP;

        roleEntity.Attack  = (int)Math.Round(jobEntity.Attack * jobLevelEntity.Attack * 0.01f);
        roleEntity.Defense = (int)Math.Round(jobEntity.Defense * jobLevelEntity.Defense * 0.01f);
        roleEntity.Hit     = (int)Math.Round(jobEntity.Hit * jobLevelEntity.Hit * 0.01f);
        roleEntity.Dodge   = (int)Math.Round(jobEntity.Dodge * jobLevelEntity.Dodge * 0.01f);
        roleEntity.Cri     = (int)Math.Round(jobEntity.Cri * jobLevelEntity.Cri * 0.01f);
        roleEntity.Res     = (int)Math.Round(jobEntity.Res * jobLevelEntity.Res * 0.01f);

        //2.计算角色装备增加的属性
        List <Role_EquipEntity> lst = Role_EquipDBModel.Instance.GetList(condition: string.Format("[RoleId]={0} and [IsPutOn]=1", roleEntity.Id));

        if (lst != null && lst.Count > 0)
        {
            for (int i = 0; i < lst.Count; i++)
            {
                Role_EquipEntity role_EquipEntity = lst[i];

                //0=HP 1=MP 2=攻击 3=防御 4=命中 5=闪避 6=暴击 7=抗性

                #region 基础属性1
                switch (role_EquipEntity.BaseAttr1Type)
                {
                case 0:
                    roleEntity.MaxHP += role_EquipEntity.BaseAttr1Value;
                    break;

                case 1:
                    roleEntity.MaxMP += role_EquipEntity.BaseAttr1Value;
                    break;

                case 2:
                    roleEntity.Attack += role_EquipEntity.BaseAttr1Value;
                    break;

                case 3:
                    roleEntity.Defense += role_EquipEntity.BaseAttr1Value;
                    break;

                case 4:
                    roleEntity.Hit += role_EquipEntity.BaseAttr1Value;
                    break;

                case 5:
                    roleEntity.Dodge += role_EquipEntity.BaseAttr1Value;
                    break;

                case 6:
                    roleEntity.Cri += role_EquipEntity.BaseAttr1Value;
                    break;

                case 7:
                    roleEntity.Res += role_EquipEntity.BaseAttr1Value;
                    break;
                }
                #endregion

                #region 基础属性2
                switch (role_EquipEntity.BaseAttr2Type)
                {
                case 0:
                    roleEntity.MaxHP += role_EquipEntity.BaseAttr2Value;
                    break;

                case 1:
                    roleEntity.MaxMP += role_EquipEntity.BaseAttr2Value;
                    break;

                case 2:
                    roleEntity.Attack += role_EquipEntity.BaseAttr2Value;
                    break;

                case 3:
                    roleEntity.Defense += role_EquipEntity.BaseAttr2Value;
                    break;

                case 4:
                    roleEntity.Hit += role_EquipEntity.BaseAttr2Value;
                    break;

                case 5:
                    roleEntity.Dodge += role_EquipEntity.BaseAttr2Value;
                    break;

                case 6:
                    roleEntity.Cri += role_EquipEntity.BaseAttr2Value;
                    break;

                case 7:
                    roleEntity.Res += role_EquipEntity.BaseAttr2Value;
                    break;
                }
                #endregion

                roleEntity.Attack  += role_EquipEntity.Attack;
                roleEntity.Defense += role_EquipEntity.Defense;
                roleEntity.Hit     += role_EquipEntity.Hit;
                roleEntity.Dodge   += role_EquipEntity.Dodge;
                roleEntity.Cri     += role_EquipEntity.Cri;
                roleEntity.Res     += role_EquipEntity.Res;
            }
        }

        //3.计算综合战斗力
        roleEntity.Fighting = roleEntity.Attack * 4 + roleEntity.Defense * 4 + roleEntity.Hit * 2 + roleEntity.Dodge * 2 + roleEntity.Cri + roleEntity.Res;

        RoleDBModel.Instance.Update(roleEntity);
    }
예제 #2
0
    //100 武器
    //200 护腕
    //300 衣服
    //400 护腿
    //500 鞋
    //600 戒指
    //700 项链
    //800 腰带

    public void EquipPutOn(int roleId, int goodsId, int goodsServerId, ref List <Role_BackpackItemChangeEntity> changeList)
    {
        //1.检查原来的装备槽上是否有装备 有的话先卸下(卸下的装备加入背包更新项 新增)
        //2.把当前装备穿戴到身上(穿戴的装备加入背包更新项目 删除)
        //3.重新计算角色战斗力(发送角色战斗里更新消息)

        MFReturnValue <object> retValue = null;

        //excel表格中的数据
        EquipEntity entity = EquipDBModel.Instance.Get(goodsId);

        //1.检查原来的装备槽上是否有装备 有的话先卸下(卸下的装备加入背包更新项 新增)
        bool isHasPutOffEquip    = false;
        int  putOffEquipServerId = 0; //脱下的装备服务器端编号

        RoleEntity roleEntity = this.GetEntity(roleId);

        switch (entity.Type)
        {
        case 100:
            if (roleEntity.Equip_Weapon > 0)
            {
                isHasPutOffEquip    = true;
                putOffEquipServerId = roleEntity.Equip_Weapon;
            }
            roleEntity.Equip_Weapon = goodsServerId;     //设置新装备
            break;

        case 200:
            if (roleEntity.Equip_Cuff > 0)
            {
                isHasPutOffEquip    = true;
                putOffEquipServerId = roleEntity.Equip_Cuff;
            }
            roleEntity.Equip_Cuff = goodsServerId;     //设置新装备
            break;

        case 300:
            if (roleEntity.Equip_Clothes > 0)
            {
                isHasPutOffEquip    = true;
                putOffEquipServerId = roleEntity.Equip_Clothes;
            }
            roleEntity.Equip_Clothes = goodsServerId;     //设置新装备
            break;

        case 400:
            if (roleEntity.Equip_Pants > 0)
            {
                isHasPutOffEquip    = true;
                putOffEquipServerId = roleEntity.Equip_Pants;
            }
            roleEntity.Equip_Pants = goodsServerId;     //设置新装备
            break;

        case 500:
            if (roleEntity.Equip_Shoe > 0)
            {
                isHasPutOffEquip    = true;
                putOffEquipServerId = roleEntity.Equip_Shoe;
            }
            roleEntity.Equip_Shoe = goodsServerId;     //设置新装备
            break;

        case 600:
            if (roleEntity.Equip_Ring > 0)
            {
                isHasPutOffEquip    = true;
                putOffEquipServerId = roleEntity.Equip_Ring;
            }
            roleEntity.Equip_Ring = goodsServerId;     //设置新装备
            break;

        case 700:
            if (roleEntity.Equip_Necklace > 0)
            {
                isHasPutOffEquip    = true;
                putOffEquipServerId = roleEntity.Equip_Necklace;
            }
            roleEntity.Equip_Necklace = goodsServerId;     //设置新装备
            break;

        case 800:
            if (roleEntity.Equip_Belt > 0)
            {
                isHasPutOffEquip    = true;
                putOffEquipServerId = roleEntity.Equip_Belt;
            }
            roleEntity.Equip_Belt = goodsServerId;     //设置新装备
            break;
        }

        if (isHasPutOffEquip)
        {
            //找到当前身上穿的武器 设置状态为脱下
            Role_EquipEntity equipPutOffEntity = Role_EquipDBModel.Instance.GetEntity(putOffEquipServerId);
            equipPutOffEntity.IsPutOn = false;
            Role_EquipDBModel.Instance.Update(equipPutOffEntity);

            //把脱下的武器加入背包
            Role_BackpackEntity backpackEntity = new Role_BackpackEntity();
            backpackEntity.Status            = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
            backpackEntity.RoleId            = roleId;
            backpackEntity.GoodsType         = (byte)0;
            backpackEntity.GoodsId           = equipPutOffEntity.EquipId;
            backpackEntity.GoodsOverlayCount = 1;
            backpackEntity.GoodsServerId     = putOffEquipServerId;
            backpackEntity.CreateTime        = DateTime.Now;
            backpackEntity.UpdateTime        = DateTime.Now;

            retValue          = Role_BackpackDBModel.Instance.Create(backpackEntity);
            backpackEntity.Id = retValue.GetOutputValue <int>("Id");

            changeList.Add(new Role_BackpackItemChangeEntity()
            {
                BackpackId    = backpackEntity.Id.Value,
                Type          = BackpackItemChangeType.Add,
                GoodsType     = GoodsType.Equip,
                GoodsId       = equipPutOffEntity.EquipId,
                GoodsCount    = 1,
                GoodsServerId = putOffEquipServerId
            });
        }

        //2.把当前装备穿戴到身上(穿戴的装备加入背包更新项目 删除)
        Role_EquipEntity equipPutOnEntity = Role_EquipDBModel.Instance.GetEntity(goodsServerId);

        equipPutOnEntity.IsPutOn = true;
        Role_EquipDBModel.Instance.Update(equipPutOnEntity);

        //查询当前装备的背包项
        Role_BackpackEntity currEquipBackpackEntity = Role_BackpackDBModel.Instance.GetEntity(string.Format(" [RoleId]={0} and [GoodsId]={1} and [GoodsType]=0 and [GoodsServerId]={2}", roleId, goodsId, goodsServerId));

        Role_BackpackDBModel.Instance.Delete(currEquipBackpackEntity.Id); //从背包中移除
        changeList.Add(new Role_BackpackItemChangeEntity()
        {
            BackpackId    = currEquipBackpackEntity.Id.Value,
            Type          = BackpackItemChangeType.Delete,
            GoodsType     = GoodsType.Equip,
            GoodsId       = goodsId,
            GoodsCount    = 1,
            GoodsServerId = goodsServerId
        });

        //3.重新计算角色战斗力
        UpdateFighting(roleEntity);
    }
예제 #3
0
    public void EquipPutOff(int roleId, int goodsId, int goodsServerId, ref List <Role_BackpackItemChangeEntity> changeList)
    {
        MFReturnValue <object> retValue = null;

        //1.把当前的装备卸下(卸下的装备加入背包更新项 新增)
        //excel表格中的数据
        EquipEntity entity = EquipDBModel.Instance.Get(goodsId);

        RoleEntity roleEntity = this.GetEntity(roleId);

        switch (entity.Type)
        {
        case 100:
            roleEntity.Equip_Weapon = -1;     //
            break;

        case 200:
            roleEntity.Equip_Cuff = -1;     //
            break;

        case 300:
            roleEntity.Equip_Clothes = -1;     //
            break;

        case 400:
            roleEntity.Equip_Pants = -1;     //
            break;

        case 500:
            roleEntity.Equip_Shoe = -1;     //
            break;

        case 600:
            roleEntity.Equip_Ring = -1;     //
            break;

        case 700:
            roleEntity.Equip_Necklace = -1;     //
            break;

        case 800:
            roleEntity.Equip_Belt = -1;     //
            break;
        }

        //找到当前身上穿的武器 设置状态为脱下
        Role_EquipEntity equipPutOffEntity = Role_EquipDBModel.Instance.GetEntity(goodsServerId);

        equipPutOffEntity.IsPutOn = false;
        Role_EquipDBModel.Instance.Update(equipPutOffEntity);

        //把脱下的武器加入背包
        Role_BackpackEntity backpackEntity = new Role_BackpackEntity();

        backpackEntity.Status            = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
        backpackEntity.RoleId            = roleId;
        backpackEntity.GoodsType         = (byte)0;
        backpackEntity.GoodsId           = goodsId;
        backpackEntity.GoodsOverlayCount = 1;
        backpackEntity.GoodsServerId     = goodsServerId;
        backpackEntity.CreateTime        = DateTime.Now;
        backpackEntity.UpdateTime        = DateTime.Now;

        retValue          = Role_BackpackDBModel.Instance.Create(backpackEntity);
        backpackEntity.Id = retValue.GetOutputValue <int>("Id");

        changeList.Add(new Role_BackpackItemChangeEntity()
        {
            BackpackId    = backpackEntity.Id.Value,
            Type          = BackpackItemChangeType.Add,
            GoodsType     = GoodsType.Equip,
            GoodsId       = goodsId,
            GoodsCount    = 1,
            GoodsServerId = goodsServerId
        });

        //2.重新计算角色战斗力(发送角色战斗里更新消息)
        UpdateFighting(roleEntity);
    }
예제 #4
0
 /// <summary>
 /// 修改
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public MFReturnValue <object> Update(Role_EquipEntity entity)
 {
     return(this.DBModel.Update(entity));
 }
예제 #5
0
    /// <summary>
    /// 物品加入背包
    /// </summary>
    /// <param name="trans">事务</param>
    /// <param name="roleId">角色编号</param>
    /// <param name="goodsInType">物品入库类型</param>
    /// <param name="goodsType">物品类型</param>
    /// <param name="goodsId">物品编号</param>
    /// <param name="goodsCount">本次物品入库的数量</param>
    private bool Add(SqlTransaction trans, int roleId, GoodsInType goodsInType, GoodsType goodsType, int goodsId, int goodsCount, ref List <Role_BackpackItemChangeEntity> changeList)
    {
        Queue <int>            goodsServerIdQueue = new Queue <int>(); //服务器端物品编号的队列
        MFReturnValue <object> retValue           = null;

        changeList = new List <Role_BackpackItemChangeEntity>();
        try
        {
            int goodsServerId = 0;
            int speed         = DateTime.Now.ToString("hhMMssfff").ToInt(); //种子

            for (int i = 0; i < goodsCount; i++)
            {
                //1.加入物品库 装备 道具 材料(根据物品类型 加入对应的物品表 如果是装备 要进行随机属性和随机属性值处理)
                switch (goodsType)
                {
                case GoodsType.Equip:
                    #region 装备入库
                    Role_EquipEntity equipEntity = new Role_EquipEntity();
                    equipEntity.Status  = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
                    equipEntity.RoleId  = roleId;
                    equipEntity.EquipId = goodsId;

                    //拿到基础装备信息
                    EquipEntity baseEntity = EquipDBModel.Instance.Get(goodsId);

                    //基础信息
                    equipEntity.BaseAttr1Type  = (byte)baseEntity.BackAttrOneType;
                    equipEntity.BaseAttr1Value = baseEntity.BackAttrOneValue;
                    equipEntity.BaseAttr2Type  = (byte)baseEntity.BackAttrTwoType;
                    equipEntity.BaseAttr2Value = baseEntity.BackAttrTwoValue;

                    //随机属性
                    //1.计算出随机属性的数量 一共是8个属性 我们随机取2-6个 也可以根据装备等级不同 随机数不同
                    int attrCount = new Random(speed).Next(2, 7);
                    speed += 100;

                    //0=HP 1=MP 2=攻击 3=防御 4=命中 5=闪避 6=暴击 7=抗性
                    int[] arr = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };

                    List <int> lst = new List <int>();
                    lst.AddRange(arr);

                    #region 随机属性
                    for (int j = 0; j < attrCount; j++)
                    {
                        //随机获取一个索引 对他进行随机值
                        //随机算法 要根据具体的项目 结合数值策划提供的算法公式来做 比如根据角色的等级 VIP等级 运气值等等来计算
                        //这里是进行最基础的随机

                        int index = new Random(speed).Next(0, lst.Count);
                        speed += 100;

                        switch (lst[index])
                        {
                        case 0:
                            equipEntity.HP = new Random(speed).Next((int)(baseEntity.HP * 0.5f), (int)(baseEntity.HP * 1.5f));
                            speed         += 100;
                            break;

                        case 1:
                            equipEntity.MP = new Random(speed).Next((int)(baseEntity.MP * 0.5f), (int)(baseEntity.MP * 1.5f));
                            speed         += 100;
                            break;

                        case 2:
                            equipEntity.Attack = new Random(speed).Next((int)(baseEntity.Attack * 0.5f), (int)(baseEntity.Attack * 1.5f));
                            speed += 100;
                            break;

                        case 3:
                            equipEntity.Res = new Random(speed).Next((int)(baseEntity.Res * 0.5f), (int)(baseEntity.Res * 1.5f));
                            speed          += 100;
                            break;

                        case 4:
                            equipEntity.Hit = new Random(speed).Next((int)(baseEntity.Hit * 0.5f), (int)(baseEntity.Hit * 1.5f));
                            speed          += 100;
                            break;

                        case 5:
                            equipEntity.Defense = new Random(speed).Next((int)(baseEntity.Defense * 0.5f), (int)(baseEntity.Defense * 1.5f));
                            speed += 100;
                            break;

                        case 6:
                            equipEntity.Dodge = new Random(speed).Next((int)(baseEntity.Dodge * 0.5f), (int)(baseEntity.Dodge * 1.5f));
                            speed            += 100;
                            break;

                        case 7:
                            equipEntity.Cri = new Random(speed).Next((int)(baseEntity.Cri * 0.5f), (int)(baseEntity.Cri * 1.5f));
                            speed          += 100;
                            break;
                        }

                        //这个索引 也就是属性用过了 就移除
                        lst.RemoveAt(index);
                    }
                    #endregion

                    equipEntity.CreateTime = DateTime.Now;
                    equipEntity.UpdateTime = DateTime.Now;

                    retValue = Role_EquipDBModel.Instance.Create(trans, equipEntity);
                    #endregion
                    break;

                case GoodsType.Item:
                    #region 道具入库
                    Role_ItemEntity itemEntity = new Role_ItemEntity();
                    itemEntity.Status     = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
                    itemEntity.RoleId     = roleId;
                    itemEntity.ItemId     = goodsId;
                    itemEntity.CreateTime = DateTime.Now;
                    itemEntity.UpdateTime = DateTime.Now;
                    retValue = Role_ItemDBModel.Instance.Create(trans, itemEntity);
                    #endregion
                    break;

                case GoodsType.Material:
                    #region 材料入库
                    Role_MaterialEntity materialEntity = new Role_MaterialEntity();
                    materialEntity.Status     = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
                    materialEntity.RoleId     = roleId;
                    materialEntity.MaterialId = goodsId;
                    materialEntity.CreateTime = DateTime.Now;
                    materialEntity.UpdateTime = DateTime.Now;
                    retValue = Role_MaterialDBModel.Instance.Create(trans, materialEntity);
                    #endregion
                    break;
                }

                if (retValue.HasError)
                {
                    return(false);
                }

                goodsServerId = retValue.OutputValues["Id"].ToInt(); //物品的服务器端编号
                goodsServerIdQueue.Enqueue(goodsServerId);

                //2.添加物品入库日志(要先从 步骤1 拿到物品的服务器端编号)
                Log_GoodsInEntity goodsInEntity = new Log_GoodsInEntity();
                goodsInEntity.Status        = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
                goodsInEntity.RoleId        = roleId;
                goodsInEntity.Type          = (byte)goodsInType;
                goodsInEntity.GoodsType     = (byte)goodsType;
                goodsInEntity.GoodsId       = goodsId;
                goodsInEntity.GoodsServerId = goodsServerId;
                goodsInEntity.CreateTime    = DateTime.Now;
                goodsInEntity.UpdateTime    = DateTime.Now;

                retValue = Log_GoodsInDBModel.Instance.Create(trans, goodsInEntity); //加入入库日志
                if (retValue.HasError)
                {
                    return(false);
                }
            }

            //3.加入背包(要进行物品的叠加处理)
            //(1).拿到物品基础表的叠加数量 装备是1 道具材料是20
            //(2).如果叠加数量是1 跳过此步骤 查询库中 该物品叠加数量最低的背包项 比如回血药 有两个背包项 20 5,那就按物品叠加数量正顺序排序 取出第一个5
            //(3).如果叠加数量是1 跳过此步骤 对这个背包项进行填充 5 -> 20
            //(4).进行剩余物品的处理 根据剩余物品的数量 该物品的叠加数量上限 动态创建背包项目 直到剩余物品全部添加完毕


            #region (1).拿到物品基础表的叠加数量 装备是1 道具材料是20
            int goodsOverlayCount = 1; //物品叠加数量
            switch (goodsType)
            {
            case GoodsType.Item:
                ItemEntity itemEntity = ItemDBModel.Instance.Get(goodsId);
                if (itemEntity != null)
                {
                    goodsOverlayCount = itemEntity.maxAmount;
                }
                break;

            case GoodsType.Material:
                MaterialEntity materialEntity = MaterialDBModel.Instance.Get(goodsId);
                if (materialEntity != null)
                {
                    goodsOverlayCount = materialEntity.maxAmount;
                }
                break;
            }
            #endregion

            #region (2).如果叠加数量是1 跳过此步骤 查询库中 该物品叠加数量最低的背包项 比如回血药 有两个背包项 20 5,那就按物品叠加数量正顺序排序 取出第一个5
            Role_BackpackEntity backpackEntity = null;
            if (goodsOverlayCount > 1)
            {
                MFReturnValue <List <Role_BackpackEntity> > retList = Role_BackpackDBModel.Instance.GetPageListWithTran(condition: string.Format("[RoleId]={0} AND [GoodsType]={1} AND [GoodsId]={2}", roleId, (byte)goodsType, goodsId), orderby: "[GoodsOverlayCount]", isDesc: false, pageSize: 1, pageIndex: 1, trans: trans);
                if (retList.HasError)
                {
                    return(false);
                }

                if (retList.Value != null && retList.Value.Count > 0)
                {
                    backpackEntity = retList.Value[0];
                }
            }
            #endregion

            #region (3).如果叠加数量是1 跳过此步骤 如果能查到背包项 对这个背包项进行填充 5 -> 20
            if (goodsOverlayCount > 1)
            {
                if (backpackEntity != null)
                {
                    //需要填充的数量 = 物品的叠加数量 - 当前背包项的叠加数量
                    int needCount = goodsOverlayCount - backpackEntity.GoodsOverlayCount;

                    if (needCount > 0)
                    {
                        int currOverlayCount = 0;
                        if (goodsCount > needCount)
                        {
                            //当前叠加数量 = 物品叠加数量
                            currOverlayCount = goodsOverlayCount;
                            goodsCount      -= needCount; //本次添加的物品数量减少
                        }
                        else
                        {
                            //当前叠加数量 = 原来的叠加数量 + 本次添加的物品数量
                            currOverlayCount = backpackEntity.GoodsOverlayCount + goodsCount;
                            goodsCount       = 0;
                        }

                        backpackEntity.GoodsOverlayCount = currOverlayCount;
                        Role_BackpackDBModel.Instance.Update(trans, backpackEntity);

                        changeList.Add(new Role_BackpackItemChangeEntity()
                        {
                            BackpackId    = backpackEntity.Id.Value,
                            Type          = BackpackItemChangeType.Update,
                            GoodsType     = (GoodsType)backpackEntity.GoodsType,
                            GoodsId       = backpackEntity.GoodsId,
                            GoodsCount    = backpackEntity.GoodsOverlayCount,
                            GoodsServerId = backpackEntity.GoodsServerId
                        });

                        Console.WriteLine("背包项修改了==>" + backpackEntity.Id.Value);
                    }
                }
            }
            #endregion

            #region (4).进行剩余物品的处理 根据剩余物品的数量 该物品的叠加数量上限 动态创建背包项目 直到剩余物品全部添加完毕
            while (goodsCount > 0)
            {
                int currOverlayCount = 0;
                if (goodsCount > goodsOverlayCount)
                {
                    currOverlayCount = goodsOverlayCount;
                    goodsCount      -= goodsOverlayCount;
                }
                else
                {
                    currOverlayCount = goodsCount;
                    goodsCount       = 0;
                }

                Role_BackpackEntity entity = new Role_BackpackEntity();
                entity.Status            = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
                entity.RoleId            = roleId;
                entity.GoodsType         = (byte)goodsType;
                entity.GoodsId           = goodsId;
                entity.GoodsOverlayCount = currOverlayCount;
                entity.GoodsServerId     = goodsServerIdQueue.Dequeue();
                entity.CreateTime        = DateTime.Now;
                entity.UpdateTime        = DateTime.Now;

                retValue = Role_BackpackDBModel.Instance.Create(trans, entity);
                if (retValue.HasError)
                {
                    return(false);
                }
                else
                {
                    entity.Id = retValue.GetOutputValue <int>("Id");
                    Console.WriteLine("背包项添加了==>" + entity.Id.Value);

                    changeList.Add(new Role_BackpackItemChangeEntity()
                    {
                        BackpackId    = entity.Id.Value,
                        Type          = BackpackItemChangeType.Add,
                        GoodsType     = (GoodsType)entity.GoodsType,
                        GoodsId       = entity.GoodsId,
                        GoodsCount    = entity.GoodsOverlayCount,
                        GoodsServerId = entity.GoodsServerId
                    });
                }
            }

            #endregion


            return(true);
        }
        catch (Exception ex)
        {
            Console.WriteLine("报错了==>" + ex.Message);
            return(false);
        }
        finally
        {
            goodsServerIdQueue.Clear();
            goodsServerIdQueue = null;

            retValue = null;
        }
    }
예제 #6
0
    private MFReturnValue <bool> Reduce(int roleId, int roleBackpackId, int goodsType, int goodsId, int goodsServerId, int count, GoodsOutType outType)
    {
        MFReturnValue <bool> retValue = new MFReturnValue <bool>();

        //1.查询物品的售价 物品的已有数量
        int  sellPrice = 0;     //售价
        int  maxAmount = 0;     //叠加数量
        int  hasCount  = 0;     //已有数量
        bool isCanSell = false; //是否可以销售

        StringBuilder sbrSql    = new StringBuilder();
        StringBuilder sbrSqlLog = new StringBuilder();

        #region 查询 售价 叠加数量 已有数量
        switch ((GoodsType)goodsType)
        {
        case GoodsType.Equip:
            EquipEntity equipEntity = EquipDBModel.Instance.Get(goodsId);
            if (equipEntity != null)
            {
                sellPrice = equipEntity.SellMoney;
                maxAmount = 1;
            }

            sbrSql.AppendFormat("[Status]=1 and [EquipId]={0}", goodsId);
            if (goodsServerId > 0)
            {
                sbrSql.AppendFormat(" and [Id]={0}", goodsServerId);
            }

            //已有数量
            hasCount = Role_EquipDBModel.Instance.GetCount(sbrSql.ToString());

            if (hasCount >= count)
            {
                isCanSell = true;
            }
            break;

        case GoodsType.Item:
            ItemEntity itemEntity = ItemDBModel.Instance.Get(goodsId);
            if (itemEntity != null)
            {
                sellPrice = itemEntity.SellMoney;
                maxAmount = itemEntity.maxAmount;
            }

            sbrSql.AppendFormat("[Status]=1 and [ItemId]={0}", goodsId);
            if (goodsServerId > 0 && maxAmount == 1)
            {
                sbrSql.AppendFormat(" and [Id]={0}", goodsServerId);
            }

            hasCount = Role_ItemDBModel.Instance.GetCount(sbrSql.ToString());

            if (hasCount >= count)
            {
                isCanSell = true;
            }

            break;

        case GoodsType.Material:
            MaterialEntity materialEntity = MaterialDBModel.Instance.Get(goodsId);
            if (materialEntity != null)
            {
                sellPrice = materialEntity.SellMoney;
                maxAmount = materialEntity.maxAmount;
            }

            sbrSql.AppendFormat("[Status]=1 and [MaterialId]={0}", goodsId);
            if (goodsServerId > 0 && maxAmount == 1)
            {
                sbrSql.AppendFormat(" and [Id]={0}", goodsServerId);
            }

            hasCount = Role_MaterialDBModel.Instance.GetCount(sbrSql.ToString());

            if (hasCount >= count)
            {
                isCanSell = true;
            }

            break;
        }
        #endregion

        //2.核对玩家拥有的物品数量是否满足出售数量
        if (!isCanSell)
        {
            retValue.HasError   = true;
            retValue.ReturnCode = -1; //数量不足
            return(retValue);
        }

        Log_GoodsInEntity  logInEntity;
        Log_GoodsOutEntity logOutEntity;
        int currGoodsServerId = 0;

        int currSellCount = count;

        //3.从对应的物品表中移除
        #region 从对应的物品表中移除
        while (currSellCount > 0)
        {
            sbrSql.Clear();
            sbrSqlLog.Clear();

            //从对应的物品表中删除
            switch ((GoodsType)goodsType)
            {
            case GoodsType.Equip:
                sbrSql.AppendFormat("[Status]=1 and [EquipId]={0}", goodsId);
                if (goodsServerId > 0)
                {
                    sbrSql.AppendFormat(" and [Id]={0}", goodsServerId);
                }
                Role_EquipEntity equipEntity = Role_EquipDBModel.Instance.GetEntity(sbrSql.ToString());
                Role_EquipDBModel.Instance.Delete(equipEntity.Id);     //删除物品
                currGoodsServerId = equipEntity.Id.Value;
                break;

            case GoodsType.Item:
                sbrSql.AppendFormat("[Status]=1 and [ItemId]={0}", goodsId);
                if (goodsServerId > 0 && maxAmount == 1)
                {
                    sbrSql.AppendFormat(" and [Id]={0}", goodsServerId);
                }
                Role_ItemEntity itemEntity = Role_ItemDBModel.Instance.GetEntity(sbrSql.ToString());
                Role_ItemDBModel.Instance.Delete(itemEntity.Id);     //删除物品
                currGoodsServerId = itemEntity.Id.Value;
                break;

            case GoodsType.Material:
                sbrSql.AppendFormat("[Status]=1 and [MaterialId]={0}", goodsId);
                if (goodsServerId > 0 && maxAmount == 1)
                {
                    sbrSql.AppendFormat(" and [Id]={0}", goodsServerId);
                }
                Role_MaterialEntity materialEntity = Role_MaterialDBModel.Instance.GetEntity(sbrSql.ToString());
                Role_MaterialDBModel.Instance.Delete(materialEntity.Id);     //删除物品
                currGoodsServerId = materialEntity.Id.Value;
                break;
            }

            sbrSqlLog.AppendFormat("[Status]=1 and [RoleId]={0} and [GoodsType]={1} and [GoodsId]={2} and [GoodsServerId]={3}",
                                   roleId, goodsType, goodsId, currGoodsServerId);

            //添加出库日志
            logInEntity = Log_GoodsInDBModel.Instance.GetEntity(sbrSqlLog.ToString()); //获取对应的入库日志

            logOutEntity               = new Log_GoodsOutEntity();
            logOutEntity.Status        = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
            logOutEntity.RoleId        = roleId;
            logOutEntity.Type          = (byte)outType;
            logOutEntity.GoodsType     = (byte)goodsType;
            logOutEntity.GoodsId       = goodsId;
            logOutEntity.GoodsServerId = currGoodsServerId;
            logOutEntity.LogGoodsInId  = logInEntity.Id.Value;
            logOutEntity.CreateTime    = DateTime.Now;
            logOutEntity.UpdateTime    = DateTime.Now;

            Log_GoodsOutDBModel.Instance.Create(logOutEntity);

            currSellCount--;
        }
        #endregion

        //4.修改或者删除对应的背包项
        currSellCount = count;

        //背包项改变列表
        List <Role_BackpackItemChangeEntity> lst = new List <Role_BackpackItemChangeEntity>();

        //roleBackpackId 更新背包项的时候,优先从这个背包项更新(修改或者删除)
        while (currSellCount > 0)
        {
            //roleBackpackId 第一次减的时候,这个背包项是肯定存在的

            //出售50个 叠加是20 当前背包项13个

            //1.先从传递过来的背包项中删除物品数量
            Role_BackpackEntity backpackEntity = null;
            if (roleBackpackId > 1)
            {
                //获取传递过来的背包项
                backpackEntity = this.GetEntity(roleBackpackId);
                roleBackpackId = 0;
            }
            else
            {
                //获取其他背包项
                backpackEntity = this.GetEntity(string.Format("[Status]=1 and [RoleId]={0} and [GoodsType]={1} and [GoodsId]={2}",
                                                              roleId, goodsType, goodsId));
            }

            if (currSellCount >= backpackEntity.GoodsOverlayCount)
            {
                //如果出售的数量 大于等于当前的背包项数量 则把这个背包项删除
                currSellCount -= backpackEntity.GoodsOverlayCount;

                //删除背包项目
                this.Delete(backpackEntity.Id);

                //添加到背包项改变列表
                lst.Add(new Role_BackpackItemChangeEntity()
                {
                    BackpackId    = backpackEntity.Id.Value,
                    Type          = BackpackItemChangeType.Delete,
                    GoodsType     = (GoodsType)goodsType,
                    GoodsId       = goodsId,
                    GoodsServerId = backpackEntity.GoodsServerId,
                    GoodsCount    = 0
                });
            }
            else
            {
                //如果出售的数量小于 当前背包项的数量 则从当前背包项中 减去出售的数量
                backpackEntity.GoodsOverlayCount -= currSellCount;
                this.Update(backpackEntity);

                //更新背包项目
                currSellCount = 0;

                //添加到背包项改变列表
                lst.Add(new Role_BackpackItemChangeEntity()
                {
                    BackpackId    = backpackEntity.Id.Value,
                    Type          = BackpackItemChangeType.Update,
                    GoodsType     = (GoodsType)goodsType,
                    GoodsId       = goodsId,
                    GoodsServerId = backpackEntity.GoodsServerId,
                    GoodsCount    = backpackEntity.GoodsOverlayCount
                });
            }
        }

        retValue.SetOutputValue("BackpackItemChange", lst);
        retValue.SetOutputValue("TotalSellPrice", sellPrice * count); //总售价 = 单价 * 数量

        return(retValue);
    }