public void SetUp() { configuration = new DiscordConfiguration(); configuration.CommandPrefix = ".dkp "; state = new AuctionState(); target = new RevealBidsCommand(configuration, state, new Mock <ILogger <RevealBidsCommand> >().Object); }
public void BeginSequences(AuctionPlayerController[] players) { _players = players; _buyerSellerSelected = new bool[_players.Length]; _isBuyer = new bool[_players.Length]; _state = AuctionState.BuyerSellerSetup; }
public Auction(string item, IEvaluationType evaluator) { Item = item; _bids = new List <Bid>(); State = AuctionState.NotStarted; _evaluator = evaluator; }
public RevealBidsCommand(DiscordConfiguration configuration, AuctionState state, ILogger <RevealBidsCommand> log) { pattern = new Regex($@"^{Regex.Escape(configuration.CommandPrefix)}\s*reveal\s+(?<auction>\d+)\s*$", RegexOptions.IgnoreCase); this.configuration = configuration; this.state = state; this.log = log; revealChannel = configuration.RevealBidsChannelName; }
public static AuctionState getAuctionStateByAuctionID(byte[] auctionID) { var data = Storage.Get(Storage.CurrentContext, new byte[] { 0x02 }.Concat(auctionID)); AuctionState state = new AuctionState(); state.id = auctionID; int seek = 0; int len = 0; len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; state.parenthash = data.Range(seek, len); seek += len; len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; state.domain = data.Range(seek, len).AsString(); seek += len; len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; state.domainTTL = data.Range(seek, len).AsBigInteger(); seek += len; len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; state.startBlockSelling = data.Range(seek, len).AsBigInteger(); seek += len; //len = (int)data.Range(seek, 2).AsBigInteger(); //seek += 2; //state.startBlockRan = data.Range(seek, len).AsBigInteger(); //seek += len; len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; state.endBlock = data.Range(seek, len).AsBigInteger(); seek += len; len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; state.maxPrice = data.Range(seek, len).AsBigInteger(); seek += len; len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; state.maxBuyer = data.Range(seek, len); seek += len; len = (int)data.Range(seek, 2).AsBigInteger(); seek += 2; state.lastBlock = data.Range(seek, len).AsBigInteger(); seek += len; return(state); }
private static bool testEnd(AuctionState state, byte[] who = null) { if (state.startBlockSelling == 0)//就没开始过 { return(false); } if (state.endBlock > 0)//已经结束了 { return(true); } var nowtime = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp; var starttime = Blockchain.GetHeader((uint)state.startBlockSelling).Timestamp; var step2time = starttime + secondday * 2; var steprantime = starttime + secondday * 3; var endtime = starttime + secondday * 5; if (nowtime < steprantime)//随机期都没到,肯定没结束 { return(false); } if (nowtime > endtime)//毫无悬念结束了 { state.endBlock = Blockchain.GetHeight(); saveAuctionState(state); return(true); } var lasttime = Blockchain.GetHeader((uint)state.lastBlock).Timestamp; if (lasttime < step2time)//阶段2没出过价 { state.endBlock = Blockchain.GetHeight(); saveAuctionState(state); return(true); } //随机期 var nowheader = Blockchain.GetHeader(Blockchain.GetHeight()); //得到当前块在整个随机期所处的位置 var persenttime = (nowheader.Timestamp - steprantime) * 1000 / (endtime - steprantime); //当处于10%位置的时候,只有10%的几率结束 if ((nowheader.ConsensusData % 1000) < persenttime) //随机数小于块位置 { state.endBlock = nowheader.Index;; //突然死亡,无法出价了 saveAuctionState(state); onRaiseEndsAuction(who, state.id); return(true); } //走到这里都没死,那就允许你出价,这里是随机期 return(false); }
public void FinishAuction() { if (State != AuctionState.AuctionOnGoing) { throw new System.InvalidOperationException("Is not possible to finish the auction before it has started."); } BidWinner = _evaluator.Evaluate(this); State = AuctionState.AuctionFinished; }
private static void saveAuctionState(AuctionState state) { var fullhash = nameHashSub(state.parenthash, state.domain); byte[] _id = Storage.Get(Storage.CurrentContext, new byte[] { 0x01 }.Concat(fullhash)); if (_id.AsBigInteger() != state.id.AsBigInteger())//没存过ID { Storage.Put(Storage.CurrentContext, new byte[] { 0x01 }.Concat(fullhash), state.id); } var key = new byte[] { 0x02 }.Concat(state.id); var doublezero = new byte[] { 0, 0 }; var data = state.parenthash; var datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); var value = datalen.Concat(data); data = state.domain.AsByteArray(); datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); value = value.Concat(datalen).Concat(data); data = state.domainTTL.AsByteArray(); datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); value = value.Concat(datalen).Concat(data); data = state.startBlockSelling.AsByteArray(); datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); value = value.Concat(datalen).Concat(data); //data = state.startBlockRan.AsByteArray(); //datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); //value = value.Concat(datalen).Concat(data); data = state.endBlock.AsByteArray(); datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); value = value.Concat(datalen).Concat(data); data = state.maxPrice.AsByteArray(); datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); value = value.Concat(datalen).Concat(data); data = state.maxBuyer; datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); value = value.Concat(datalen).Concat(data); data = state.lastBlock.AsByteArray(); datalen = ((BigInteger)data.Length).AsByteArray().Concat(doublezero).Range(0, 2); value = value.Concat(datalen).Concat(data); onAuctionState(state); Storage.Put(Storage.CurrentContext, key, value); }
public static AuctionState getAuctionStateByFullhash(byte[] fullhash) { //需要保存每一笔拍卖记录,因为过去拍卖者的资金都要锁定在这里 byte[] id = Storage.Get(Storage.CurrentContext, new byte[] { 0x01 }.Concat(fullhash)); if (id.Length == 0)//没在销售中 { AuctionState _state = new AuctionState(); _state.id = new byte[0]; _state.startBlockSelling = 0; return(_state); } return(getAuctionStateByAuctionID(id)); }
public static AuctionState getAuctionStateByAuctionID(byte[] auctionID) { var data = Storage.Get(Storage.CurrentContext, new byte[] { 0x02 }.Concat(auctionID)); if (data.Length <= 0) { var auctionState = new AuctionState(); auctionState.id = new byte[0]; auctionState.startBlockSelling = 0; return(auctionState); } return(Helper.Deserialize(data) as AuctionState); }
private static void saveAuctionState(AuctionState state) { var fullhash = nameHashSub(state.parenthash, state.domain); byte[] _id = Storage.Get(Storage.CurrentContext, new byte[] { 0x01 }.Concat(fullhash)); if (_id.AsBigInteger() != state.id.AsBigInteger())//没存过ID { Storage.Put(Storage.CurrentContext, new byte[] { 0x01 }.Concat(fullhash), state.id); } var key = new byte[] { 0x02 }.Concat(state.id); onChangeAuctionState(state); Storage.Put(Storage.CurrentContext, key, Helper.Serialize(state)); }
public static string ToText(this AuctionState state) { switch (state) { case AuctionState.Created: return("Leilão não iniciado"); case AuctionState.InProgress: return("Leilão em andamento"); case AuctionState.Closed: return("Leilão encerrado"); default: return("Estado não encontrado"); } }
public string getAuctionStateByFullDomain(string domain, int minuteOfDay = 1440) { JArray inputJA = JArray.Parse(string.Format(@" [ '(str)getAuctionStateByFullhash', [ '(hex256){0}' ] ]", domain.getNamehashForInvoke())); JObject result = cop.nelApi.invokeScript(neoHelper.Jarray2script(cop.contractHash, inputJA)); JArray stackJA = (JArray)result["result"][0]["stack"][0]["value"]; AuctionState AS = new AuctionState(); AS.id = ((string)stackJA[0]["value"]).HexstringReverse(); if (AS.id != "") { AS.auctionStarter = ThinNeo.Helper_NEO.GetAddress_FromScriptHash(((string)stackJA[1]["value"]).Hexstring2Bytes()); AS.parenthash = (string)stackJA[2]["value"]; AS.domain = ((string)stackJA[3]["value"]).Hexstring2String(); AS.domainTTL = startTime.AddSeconds((double)((string)stackJA[4]["value"]).Hexstring2Decimal(0)); AS.startBlockSelling = (Int64)stackJA[5]["value"]; DateTime start = startTime.AddSeconds(cop.nelApi.getBlockTimeStamp(AS.startBlockSelling)); //按设置换算天数,默认24小数*60.test为5 AS.day = ((DateTime.Now - start).TotalMinutes) / minuteOfDay; try { AS.endBlock = (Int64)stackJA[6]["value"]; } catch { AS.endBlock = 0; } try { AS.maxPrice = (decimal)((int)stackJA[7]["value"] / Math.Pow(10, 8)); } catch { AS.maxPrice = 0; } try { AS.maxBuyer = ThinNeo.Helper_NEO.GetAddress_FromScriptHash(((string)stackJA[8]["value"]).Hexstring2Bytes()); } catch { AS.maxBuyer = ""; } try { AS.lastBlock = (Int64)stackJA[9]["value"]; } catch { AS.lastBlock = 0; } } string ASstr = JsonConvert.SerializeObject(AS); ASstr = JObject.Parse(ASstr).ToString(); return(ASstr); }
public static bool RandomEnd(AuctionState state, uint starttime, byte[] who) { var step2time = starttime + secondday * 2; var steprantime = starttime + secondday * 3; var endtime = starttime + secondday * 5; var nowheader = Blockchain.GetHeader(Blockchain.GetHeight()); //得到当前块在整个随机期所处的位置 var persenttime = (nowheader.Timestamp - steprantime) * 1000 / (endtime - steprantime); //当处于10%位置的时候,只有10%的几率结束 if ((nowheader.ConsensusData % 1000) < persenttime) //随机数小于块位置 { state.endBlock = nowheader.Index;; //突然死亡,无法出价了 saveAuctionState(state); onRaiseEndsAuction(who, state.id); return(true); } return(false); }
public void SetUp() { state = new AuctionState(); dkpProcessor = new Mock <IDkpProcessor>(); itemProcessor = new Mock <IItemProcessor>(); configuration = new DkpBotConfiguration { Ranks = new[] { alt, box, main } }; raid = new RaidInfo(); Mock <IMessageChannel> channel = new Mock <IMessageChannel>(); channel.Setup(x => x.SendMessageAsync(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <Embed>(), It.IsAny <RequestOptions>())) .Returns(Task.FromResult(new Mock <IUserMessage>().Object)); message = new Mock <IMessage>(); message.SetupGet(x => x.Channel).Returns(channel.Object); target = new AuctionProcessor(configuration, state, itemProcessor.Object, dkpProcessor.Object, new Mock <ILogger <AuctionProcessor> >().Object); }
//判断域名拍卖有没有结束 private static bool IsAuctionEnd(AuctionState state, uint starttime, uint nowtime) { //if (state.startBlockSelling == 0)//就没开始过 // return false; if (state.endBlock > 0)//已经结束了 { return(true); } var step2time = starttime + secondday * 2; var steprantime = starttime + secondday * 3; var endtime = starttime + secondday * 5; if (nowtime < steprantime)//随机期都没到,肯定没结束 { return(false); } if (nowtime >= endtime)//毫无悬念结束了 { state.endBlock = Blockchain.GetHeight(); saveAuctionState(state); return(true); } var lasttime = Blockchain.GetHeader((uint)state.lastBlock).Timestamp; if (lasttime < step2time)//阶段2没出过价 { state.endBlock = Blockchain.GetHeight(); saveAuctionState(state); return(true); } //随机期 判断此期间有没有结束用endblock来判断 这个上面已经判断过了 //走到这里都没死,那就允许你出价,这里是随机期 return(false); }
public static bool startAuction(byte[] who, byte[] hash, string domainname) { //判断域名的合法性 //域名的有效性 只能是a~z 0~9 2~32长 if (domainname.Length < 2 || domainname.Length > 32) { return(false); } foreach (var c in domainname) { if (!((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))) { return(false); } } var domaininfo = getOwnerInfo(hash); //先看这个域名归我管不 if (domaininfo.register.AsBigInteger() != ExecutionEngine.ExecutingScriptHash.AsBigInteger()) { return(false); } //再看看域名能不能拍卖 var fullhash = nameHashSub(hash, domainname); var info = getOwnerInfo(fullhash); var inuse = getDomainUseState(info); if (inuse == DomainUseState.InUse) { return(false); } //再看看有没有在拍卖 var selling = getAuctionStateByFullhash(fullhash); if (selling.startBlockSelling > 0) //已经在拍卖中了 { if (testEnd(selling) == false) //拍卖未结束不准 { return(false); } if (selling.maxBuyer.Length > 0)//未流拍的拍卖,一年内不得再拍 { var nowtime = Blockchain.GetHeader(Blockchain.GetHeight()).Timestamp; var starttime = Blockchain.GetHeader((uint)selling.startBlockSelling).Timestamp; if ((nowtime - starttime) < secondyear) { return(false); } } } AuctionState sell = new AuctionState(); sell.parenthash = hash; sell.domain = domainname; sell.domainTTL = info.TTL; sell.startBlockSelling = Blockchain.GetHeight();//开始拍卖了 //sell.startBlockRan = 0;//随机块现在还不能确定 sell.endBlock = 0; sell.maxPrice = 0; sell.maxBuyer = new byte[0]; sell.lastBlock = 0; var txid = (ExecutionEngine.ScriptContainer as Transaction).Hash; sell.id = txid; saveAuctionState(sell); //onAddPrice(who, 0); return(true); }
public IEnumerator ShowChoices() { yield return(new WaitForSeconds(5)); _state = AuctionState.AuctionSetup; }
private void Update() { Debug.Log("State : " + _state.ToString()); #region Wait if (_state == AuctionState.Wait) { //nothing } #endregion #region Buyer / Seller Setup else if (_state == AuctionState.BuyerSellerSetup) { for (int i = 0; i < _players.Length; i++) { _buyerSellerSelected = new bool[_players.Length]; _isBuyer = new bool[_players.Length]; _players[i].SetOreType(_resourcesToTrade[_resourceIndex]); _players[i].SetBuyerSellerSelectPhase(); } _auctionMaterialTitle.text = "current auction: " + _resourcesToTrade[_resourceIndex]; _state = AuctionState.BuyerSellerSelect; } #endregion #region Buyer / Seller Select else if (_state == AuctionState.BuyerSellerSelect) //wait for everyone to choose if theyre a buyer or seller { bool allDone = true; for (int i = 0; i < _buyerSellerSelected.Length; i++) { if (!_buyerSellerSelected[i]) { allDone = false; } } if (allDone) { _state = AuctionState.Wait; StartCoroutine(ShowChoices()); } } #endregion #region Setup Auction else if (_state == AuctionState.AuctionSetup) { _currentBuyMax = 15; _currentSellMin = 50; _sellLine.SetActive(true); _buyLine.SetActive(true); _sellLine.transform.position = _ceilingLoc.position; _buyLine.transform.position = _floorLoc.position; for (int i = 0; i < _players.Length; i++) { _players[i].isBuyer = _isBuyer[i]; if (_players[i].isBuyer) { _players[i].currentPrice = _currentBuyMax; } else { _players[i].currentPrice = _currentSellMin; } _players[i].SetAuctionPhase(); } _state = AuctionState.AuctionHappening; } #endregion #region Auction Phase else if (_state == AuctionState.AuctionHappening) { int minSell = SetSellLine(); int maxBuy = SetBuyLine(); for (int i = 0; i < _players.Length; i++) { if (_players[i].isBuyer) { _players[i].SetNewBounds(15, minSell); } else { _players[i].SetNewBounds(maxBuy, 50); } } //ok now see if we have a sale on our hands if (_transactionTimer < 0) { for (int i = 0; i < _players.Length; i++) { if (_players[i].isBuyer) { //there is a buyer in our midst if (_players[i].currentPrice == maxBuy && i == _currentBuyerPlayer && maxBuy == minSell) { GameData.Instance.companies[i].money -= maxBuy; GameData.Instance.companies[i].oreSupplies[_resourcesToTrade[_resourceIndex]] += 5; } } else { //there is a seller in our midst if (_players[i].currentPrice == minSell && i == _currentSellerPlayer && maxBuy == minSell) { GameData.Instance.companies[i].money += maxBuy; GameData.Instance.companies[i].oreSupplies[_resourcesToTrade[_resourceIndex]] -= 5; } } } _transactionTimer = 1; } _transactionTimer -= Time.deltaTime; _auctionTimer -= Time.deltaTime; if (_auctionTimer < 0 || Input.GetKeyUp(KeyCode.P)) { _resourceIndex++; if (_resourceIndex >= _resourcesToTrade.Length) { LeaveAuction(); } else { _state = AuctionState.EndAuction; } _auctionTimer = 40; } } #endregion #region End of Auction else if (_state == AuctionState.EndAuction) { _sellLine.SetActive(false); _buyLine.SetActive(false); _state = AuctionState.BuyerSellerSetup; } #endregion }
public void StartAuction() { State = AuctionState.AuctionOnGoing; }
public static void StartAuction(Client client) { if (client.Player.CharID == AuctionMaster) { if (client.Player.MapID == AUCTION_MAP) { State = AuctionState.Started; highestBidder = null; highestBid = -1; IMap playerMap = client.Player.Map; foreach (Client i in playerMap.GetClients()) { Messenger.BattleMsg(i, "The auction for a " + SetItem + " has begun! Say /bid bidinpoke to make a bid!", Text.Yellow); Messenger.PlayerMsg(i, "The auction for a " + SetItem + " has begun! Say /bid bidinpoke to make a bid!", Text.Yellow); } } } }
public static void EndAuction(Client client) { if (client.Player.CharID == AuctionMaster || Ranks.IsAllowed(client, Enums.Rank.Developer)) { if (client.Player.MapID == AUCTION_MAP) { if (State == AuctionState.Pending) { State = AuctionState.NotStarted; AuctionMaster = null; IMap playerMap = client.Player.Map; foreach (Client i in playerMap.GetClients()) { Messenger.PlayerMsg(i, "The auction has ended.", Text.Yellow); //Messenger.SendBattleDivider(i); //Messenger.PlayerMsg(client, "The auction has been ended!", Text.Yellow); } } else if (State == AuctionState.Started) { State = AuctionState.NotStarted; //LastAuctionMaster = AuctionMaster; AuctionMaster = null; // if (Ranks.IsDisallowed(client, Enums.Rank.Developer)) { // AuctionMaster = null; // } IMap playerMap = client.Player.Map; foreach (Client i in playerMap.GetClients()) { Messenger.PlayerMsg(i, "The auction has ended. The winner was " + ClientManager.FindClient(highestBidder).Player.Name + " with a bid of " + highestBid.ToString(), Text.Yellow); Messenger.SendBattleDivider(i); //Messenger.PlayerMsg(client, "The auction has been ended!", Text.Yellow); } } } else { Messenger.PlayerMsg(client, "No auction has been started yet!", Text.BrightRed); } } }
public static void CreateAuction(Client auctionMaster) { //if (Ranks.IsAllowed(auctionMaster, Enums.Rank.Developer)) { if (string.IsNullOrEmpty(AuctionMaster)) { AuctionMaster = auctionMaster.Player.CharID; State = AuctionState.Pending; // modified for testing Messenger.PlayerMsg(auctionMaster, "You have created a new auction. Say /auctionadminhelp for commands on what to do next.", Text.Yellow); } else { Messenger.PlayerMsg(auctionMaster, "An auction is already in progress!", Text.BrightRed); } //} else { // Messenger.PlayerMsg(auctionMaster, "You do not have a high enough access to start an auction!", Text.BrightRed); //} }