You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

356 lines
14 KiB

//using Google.Protobuf.WellKnownTypes;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Net.NetworkInformation;
//using System.Runtime.Serialization;
//using System.Text;
//using System.Threading.Tasks;
//namespace SogClient
//{
// public class TestTrade : ITestHandler
// {
// private Player player = null;
// public TestTrade(Player player) : base(player)
// {
// this.player = player;
// TraceLog.Debug("TestTrade player {0}", player.GetUid());
// }
// private enum OpState
// {
// LOCK,
// UNLOCK,
// NOTOPEN,
// OPEN,
// MATCH,
// TRADEING,
// FINISH
// }
// public override void RegisterMsg(TestHandlerMgr mgr)
// {
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeInfores, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeJoinres, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeMatch, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeMaininfo, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeFresh, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeSellres, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeBuyres, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeDepotbuyres, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeFinish, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeGetrewardRes, this);
// mgr.RegisterPacketHandler((int)CSGameMsgID.TradeRankres, this);
// }
// private long m_lastUpdateTime;
// private OpState m_opState = OpState.LOCK;
// private long m_willOpenTimeSec;
// private CSTradeMainInfo mainInfo;
// private bool hasReward = false;
// public override void Update(long nowSecond)
// {
// if (m_lastUpdateTime == 0)
// {
// m_lastUpdateTime = nowSecond;
// }
// //cd 5s,太短压力测试时gate撑不住
// if (m_lastUpdateTime + 5 > nowSecond)
// {
// return;
// }
// m_lastUpdateTime = nowSecond;
// if (m_opState == OpState.LOCK)
// {
// if (!player.IsUnlockSys((int)SystemUnlockId.Trade))
// {
// //发送gm开启
// player.SendGM("AddItem 3 200000");
// player.SendGM("TaskEXJumpMain 173 " + player.GetUid());
// TraceLog.Debug("发送GM开启 {0}", player.GetUid());
// }
// //else if (m_opState == OpState.LOCK)
// //{
// m_opState = OpState.UNLOCK;
// CSTradeActInfoReq req = new CSTradeActInfoReq();
// SendToServer(req, (int)CSGameMsgID.TradeInforeq);
// //}
// }
// else if (m_opState == OpState.NOTOPEN)
// {
// if(nowSecond >= m_willOpenTimeSec)
// {
// m_opState = OpState.UNLOCK;
// CSTradeActInfoReq req = new CSTradeActInfoReq();
// SendToServer(req, (int)CSGameMsgID.TradeInforeq);
// }
// }else if(m_opState == OpState.FINISH)
// {
// if (!hasReward)
// {
// CSTradeActInfoReq req = new CSTradeActInfoReq();
// SendToServer(req, (int)CSGameMsgID.TradeInforeq);
// }
// }
// }
// public override void HandlerMsg(RequestPacket packet)
// {
// switch (packet.MsgID)
// {
// case (int)CSGameMsgID.TradeInfores:
// TradeInfores(packet);
// break;
// case (int)CSGameMsgID.TradeJoinres:
// TradeJoinres(packet);
// break;
// case (int)CSGameMsgID.TradeMatch:
// TradeMatch(packet);
// break;
// case (int)CSGameMsgID.TradeMaininfo:
// TradeMaininfo(packet);
// break;
// case (int)CSGameMsgID.TradeFresh:
// TradeFresh(packet);
// break;
// case (int)CSGameMsgID.TradeBuyres:
// TradeBuyres(packet);
// break;
// case (int)CSGameMsgID.TradeSellres:
// TradeSellres(packet);
// break;
// case (int)CSGameMsgID.TradeFinish:
// TradeFinish(packet);
// break;
// case (int)CSGameMsgID.TradeRankres:
// TradeRankres(packet);
// break;
// case (int)CSGameMsgID.TradeGetrewardRes:
// TradeGetrewardRes(packet);
// break;
// case (int)CSGameMsgID.TradeDepotbuyres:
// TradeDepotbuyres(packet);
// break;
// }
// }
// private void TradeDepotbuyres(RequestPacket packet)
// {
// if (mainInfo == null) return;
// CSTradeDepotBuyRes res = packet.Packet as CSTradeDepotBuyRes;
// TraceLog.Debug("TradeDepotbuyres {0} ", res);
// mainInfo.Coin = res.Coin;
// mainInfo.DepotBuyCount = res.DepotBuyCount;
// }
// private void TradeGetrewardRes(RequestPacket packet)
// {
// CSTradeGetRankRewardRes res = packet.Packet as CSTradeGetRankRewardRes;
// TraceLog.Debug("TradeGetrewardRes {0} ", res);
// hasReward = false;
// }
// private void TradeRankres(RequestPacket packet)
// {
// CSTradeRankRes res = packet.Packet as CSTradeRankRes;
// TraceLog.Debug("CSTradeRankRes {0} ", res);
// if (hasReward)
// {
// CSTradeGetRankReward req = new CSTradeGetRankReward(); ;
// req.Rank = res.Myrank;
// SendToServer(req, (int)CSGameMsgID.TradeGetreward);
// }
// }
// private void TradeFinish(RequestPacket packet)
// {
// TraceLog.Debug("TradeFinish {0} ", player.GetUid());
// m_opState = OpState.FINISH;
// hasReward = true;
// CSTradeRankReq req = new CSTradeRankReq();
// SendToServer(req, (int)CSGameMsgID.TradeRankreq);
// }
// private void TradeBuyres(RequestPacket packet)
// {
// if (mainInfo == null) return;
// CSTradeBuyRes res = packet.Packet as CSTradeBuyRes;
// if(res.Ret != CSErrCode.None) {
// TraceLog.Debug("TradeBuyres {0} , {1}, {2} ", res, mainInfo.Coin, mainInfo.DepotGoods);
// return;
// }
// bool exist = false;
// for(int i = 0;i < mainInfo.DepotGoods.Count;i++)
// {
// if (mainInfo.DepotGoods[i].Id == res.Goods.Id)
// {
// mainInfo.DepotGoods[i].Price = res.Goods.Price;
// mainInfo.DepotGoods[i].Count = res.Goods.Count;
// exist = true;
// break;
// }
// }
// if (!exist)
// {
// mainInfo.DepotGoods.Add(res.Goods);
// }
// mainInfo.Coin = res.Coin;
// TraceLog.Debug("TradeBuyres {0} , {1}, {2}, {3} ", player.GetUid(), res, mainInfo.Coin, mainInfo.DepotGoods);
// }
// private void TradeSellres(RequestPacket packet)
// {
// if (mainInfo == null) return;
// CSTradeSellRes res = packet.Packet as CSTradeSellRes;
// for (int i = 0; i < mainInfo.DepotGoods.Count; i++)
// {
// if (mainInfo.DepotGoods[i].Id == res.Goods.Id)
// {
// mainInfo.DepotGoods[i].Price = res.Goods.Price;
// mainInfo.DepotGoods[i].Count = res.Goods.Count;
// break;
// }
// }
// mainInfo.Coin = res.Coin;
// TraceLog.Debug("TradeSellres {0} , {1}, {2}, {3} ", player.GetUid(), res, mainInfo.Coin, mainInfo.DepotGoods);
// }
// private void TradeFresh(RequestPacket packet)
// {
// CSTradeFresh res = packet.Packet as CSTradeFresh;
// TraceLog.Debug("TradeFresh {0}, {1} ", player.GetUid(), res);
// if (this.mainInfo != null)
// {
// this.mainInfo.Ship = res.Ship;
// RandomSell();
// RandomBuy();
// }
// }
// private void RandomSell()
// {
// //有赚钱的就卖
// for (int i = 0; i < mainInfo.DepotGoods.Count; i++)
// {
// int goodid = mainInfo.DepotGoods[i].Id;
// int price = mainInfo.DepotGoods[i].Price / 100;
// int count = mainInfo.DepotGoods[i].Count;
// for (int j = 0; j < mainInfo.Ship.Goods.Count; j++)
// {
// if (goodid == mainInfo.Ship.Goods[j].Id
// && price < mainInfo.Ship.Goods[j].Price)
// {
// CSTradeSellReq req = new CSTradeSellReq();
// req.Round = mainInfo.Ship.Round;
// req.GoodsId = goodid;
// req.Count = count;
// SendToServer(req, (int)CSGameMsgID.TradeSellreq);
// }
// }
// }
// }
// private void RandomBuy()
// {
// //随机70%购买一半钱的货物
// int r = Random.Shared.Next(100);
// if (r <= 70)
// {
// int stocksize = 0;
// for (int i = 0; i < mainInfo.DepotGoods.Count; i++)
// {
// stocksize += mainInfo.DepotGoods[i].Count;
// }
// int usecoin = (int)(this.mainInfo.Coin * 0.5);
// for (int i = 0; i < mainInfo.Ship.Goods.Count; i++)
// {
// r = Random.Shared.Next(100);
// if(r < 50)
// {
// continue;
// }
// int p = mainInfo.Ship.Goods[i].Price;
// int c = usecoin / p;
// if (c > 0)
// {
// if (c + stocksize > mainInfo.DepotSize)
// {
// c = mainInfo.DepotSize - stocksize;
// }
// if (c > 0)
// {
// CSTradeBuyReq req = new CSTradeBuyReq();
// req.Round = mainInfo.Ship.Round;
// req.GoodsId = mainInfo.Ship.Goods[i].Id;
// req.Count = c;
// SendToServer(req, (int)CSGameMsgID.TradeBuyreq);
// break;
// }
// }
// }
// }
// else
// {
// TraceLog.Debug("Round {0} {1}不买", mainInfo.Ship.Round, player.GetUid());
// //50%概率,扩容一次仓库
// r = Random.Shared.Next(100);
// if (r <= 50)
// {
// if (mainInfo.DepotSize < 600)
// {
// //8000; 40000; 160000; 480000; 960000
// int[] needs = { 8000, 40000, 160000, 480000, 960000 };
// int need = needs[mainInfo.DepotBuyCount];
// if (need <= mainInfo.Coin)
// {
// CSTradeDepotBuyReq req = new CSTradeDepotBuyReq();
// SendToServer(req, (int)CSGameMsgID.TradeDepotbuyreq);
// }
// }
// }
// }
// }
// private void TradeMaininfo(RequestPacket packet)
// {
// CSTradeMainInfo res = packet.Packet as CSTradeMainInfo;
// TraceLog.Debug("TradeMaininfo {0} ", res);
// m_opState = OpState.TRADEING;
// this.mainInfo = res;
// RandomBuy();
// }
// private void TradeJoinres(RequestPacket packet)
// {
// CSTradeActJoinRes res = packet.Packet as CSTradeActJoinRes;
// TraceLog.Debug("TradeJoinres {0} ", res.Ret);
// }
// private void TradeMatch(RequestPacket packet)
// {
// TraceLog.Debug("TradeMatch {0} ", player.GetUid());
// m_opState = OpState.MATCH;
// }
// private void TradeInfores(RequestPacket packet)
// {
// CSTradeActInfoRes res = packet.Packet as CSTradeActInfoRes;
// TraceLog.Debug("TradeInfores {0} ", res);
// if(res.Status == 2)
// {
// m_opState = OpState.OPEN;
// //开启
// if (res.InRoom || res.Times > 0)
// {
// CSTradeActJoinReq req = new CSTradeActJoinReq();
// SendToServer(req, (int)CSGameMsgID.TradeJoinreq);
// }else if(res.Times <= 0)
// {
// player.SendGM("Trade AddTimes 99");
// CSTradeActJoinReq req = new CSTradeActJoinReq();
// SendToServer(req, (int)CSGameMsgID.TradeJoinreq);
// }
// }
// else
// {
// m_opState = OpState.NOTOPEN;
// m_willOpenTimeSec = TimeUtils.GetTimeSecond() + res.RemainTimeSec ;
// if (res.RankReward)
// {
// hasReward = true;
// CSTradeRankReq req = new CSTradeRankReq();
// SendToServer(req, (int)CSGameMsgID.TradeRankreq);
// }
// }
// }
// }
//}