public static string BuyMessage(DateTime timestamp, BuyAction a) { string currency = WorldObjectManager.GetFromID(a.WorldObjectId).GetComponent <CreditComponent>().CurrencyName; TradeOffer offer = (from TradeOffer o in WorldObjectManager.GetFromID(a.WorldObjectId).GetComponent <StoreComponent>().SellOffers() where o.Stack.Item.FriendlyName == a.ItemTypeName select o).FirstOrDefault(); return($"Buy(timestamp={timestamp:u}, worldtime={a.TimeSeconds}, item={a.ItemTypeName}, price={offer.Price}, currency={currency}, user={a.Username})\n"); }
private static string GetBuyActionReport(BuyAction act) { return(String.Format( "Agent {0} is buying {1} units of {2} from {3} for {4} credits total ({5} credits per unit).", act.Buyer.AgentNumber, act.Quantity, act.Purchasable.Stack.Good.Name, act.Purchasable.SellersNumber, act.Purchasable.PricePerUnit * act.Quantity, act.Purchasable.PricePerUnit)); }
public object ParseFromMsg(Dictionary <string, object> args) { type = Type.Move + Convert.ToInt32(args["type"]); move = null; buy = null; if (type == Type.Move || type == Type.Move_And_Buy) { move = new MoveAction( new Position(Convert.ToInt32(args["move_src_r"]), Convert.ToInt32(args["move_src_c"])), new Position(Convert.ToInt32(args["move_dst_r"]), Convert.ToInt32(args["move_dst_c"]))); } if (type == Type.Buy || type == Type.Move_And_Buy) { buy = new BuyAction() { type = Unit.TypeEnum.Bread + Convert.ToInt32(args["buy_type"]), status = BuyAction.Status.Before_Move + Convert.ToInt32(args["buy_status"]) }; } return(this); }
public override List <Action> GenerateSatisfyingActions(IWorldState worldState, int maxActions) { List <BuyOption> options = new List <BuyOption>(); IEntity owner = worldState.GetEntity(ownerId); foreach (Merchant m in worldState.GetMerchants()) { int bestIndex = -1; for (int i = 0; i < m.saleEntries.Count; i++) { if (itemFilter.Satisfied(m.saleEntries[i].itemTemplate.Expected())) { if (bestIndex == -1 || m.saleEntries[bestIndex].price < m.saleEntries[i].price) { bestIndex = i; } } } if (bestIndex != -1) { float dist = PathFinder.EstimateDistance(owner.Position, m.position); options.Add(new BuyOption(m, dist, bestIndex)); } } //Debug.Log($"Found {options.Count} options"); options.Sort((x, y) => x.dist.CompareTo(y.dist)); List <Action> actions = new List <Action>(); for (int i = 0; i < Mathf.Min(maxActions, options.Count); i++) { BuyAction buyAction = new BuyAction(worldState, ownerId, options[i].saleEntryIndex, options[i].merchant.id); actions.Add(buyAction); } return(actions); }
protected void ImageButtonBuy_Click(object sender, ImageClickEventArgs e) { if (Session["UserId"] != null) { DataTable dt = new DataTable(); DataSet ds = new DataSet(); SqlConnection sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["ShopConnectionString"].ConnectionString); SqlDataAdapter sda = new SqlDataAdapter("sp_buyActionOfferInfo", sqlConn); sda.SelectCommand.CommandType = CommandType.StoredProcedure; sda.SelectCommand.Parameters.Add("@OfferId", SqlDbType.Int).Value = Convert.ToInt32(Request.QueryString["ItemId"]); sda.Fill(ds); dt = ds.Tables[0]; if (dt.Rows.Count == 0) //offer doesn't exist { PanelError.Visible = true; PanelProcess.Visible = false; PanelSuccessful.Visible = false; ImageError.ImageUrl = "~/images/messages/notfound.png"; } else //offer exists { DateTime Deadline = Convert.ToDateTime(dt.Rows[0]["EndDate"].ToString()); if (DateTime.Now <= Deadline) { DataTable dtUser = new DataTable(); DataSet ds2 = new DataSet(); SqlDataAdapter sda2 = new SqlDataAdapter("sp_buyActionUserCreditInfo", sqlConn); sda2.SelectCommand.CommandType = CommandType.StoredProcedure; sda2.SelectCommand.Parameters.Add("@UserId", SqlDbType.Int).Value = Convert.ToInt32(Session["UserId"]); sda2.Fill(ds2); dtUser = ds2.Tables[0]; int GiftCredit = 0; int AllPrice = Convert.ToInt32(DropDownListQuantity.SelectedValue) * Convert.ToInt32(dt.Rows[0]["PriceOffer"].ToString()) + Convert.ToInt32(LabelPostPrice.Text); int AllGift = Convert.ToInt32(DropDownListQuantity.SelectedValue) * Convert.ToInt32(dt.Rows[0]["PriceGift"].ToString()); int UserGift = Convert.ToInt32(dtUser.Rows[0]["GiftCredit"].ToString()); int UserCredit = Convert.ToInt32(dtUser.Rows[0]["Credit"].ToString()); if (AllGift > UserGift) { GiftCredit = UserGift; } else { GiftCredit = AllGift; } int UserPayment = AllPrice - GiftCredit; if (UserCredit >= UserPayment) { PanelError.Visible = false; PanelProcess.Visible = false; PanelSuccessful.Visible = true; BuyAction ba = new BuyAction(); LabelCode.Text = ba.buyAction("Offers", Convert.ToInt32(Session["UserId"]), Convert.ToInt32(Request.QueryString["ItemId"]), Convert.ToInt32(DropDownListQuantity.SelectedValue), UserPayment, GiftCredit); LabelQuantity.Text = DropDownListQuantity.SelectedValue; NotificationsClass nc = new NotificationsClass(); nc.addNotification(1, Convert.ToInt32(Session["UserId"]), 2, HyperLinkTitle.Text, ""); } else { PanelNoCredit.Visible = true; PanelProcess.Visible = true; LabelCurrentCredit.Text = dtUser.Rows[0]["Credit"].ToString(); LabelCreditDifference.Text = (UserPayment - UserCredit).ToString(); } sda2.Dispose(); } else if (DateTime.Now > Deadline) { PanelError.Visible = true; PanelProcess.Visible = false; PanelSuccessful.Visible = false; ImageError.ImageUrl = "~/images/messages/expired.png"; } } sda.Dispose(); sqlConn.Close(); } else { PanelError.Visible = true; PanelProcess.Visible = false; PanelSuccessful.Visible = false; ImageError.ImageUrl = "~/images/messages/loginfirst.png"; } }
public PlayerAction(MoveAction move, BuyAction buy) { type = Type.Move_And_Buy; this.move = move; this.buy = buy; }
public PlayerAction(BuyAction buy) { type = Type.Buy; this.buy = buy; }
public async Task Buy (string sessionId, PieceType pieceType) { await Clients.Caller.SendAsync( "LogMessage", $"Received Request - Buy ({sessionId} - {pieceType})" ); UserModel user = await userManager.GetUserAsync( Context.GetHttpContext().User ); BuyAction action = await gameActionService.BuyAction( sessionId, user.UserId, pieceType ); await DoAction( action ); }
private void HandleBuyAction(BuyAction ba) { DateTime now = DateTime.Now; ChatManager.ServerMessageToAllLoc(EcoAnalyzerProtocol1.BuyMessage(now, ba), false, category: ChatCategory.Info); }
public AI_Action(MoveAction move, BuyAction buy) { type = Type.Move_And_Buy; this.move = move; this.buy = buy; }
public AI_Action(BuyAction buy) { type = Type.Buy; this.buy = buy; }
public async Task <Unit> Buy(List <Action> actions) { var unit = await R.shop.Buy(this); if (!unit) { return(null); } var thisPos = transform.position.WorldToArray(); R.info.UpdateUnitUI(thisPos); var prevUnit = Unit.array[thisPos.x][thisPos.y] == unit ? null : Unit.array[thisPos.x][thisPos.y]; int?prevTombstoneTurn = Tombstone.array[thisPos.x][thisPos.y]?.turn; isBuying = true; // Local lambda System.Action cancelUnit = async() => { army.money += unit.cost; (await unit.Die())?.Destroy(); Unit.array[thisPos.x][thisPos.y] = prevUnit; if (prevTombstoneTurn != null) { Tombstone.NewOrUpdate(transform.position, (int)prevTombstoneTurn); } isBuying = false; }; if (prevUnit) { --prevUnit.spriteRenderer.sortingOrder; } var buyAction = new BuyAction(thisPos, unit.name); while (true) { R.input.click = null; actions.Clear(); actions.Add(buyAction); var result = await unit.OnAction(actions); switch (result) { case Unit.ResultOnAction.SUCCESSFULED: isBuying = false; if (prevUnit) { ++prevUnit.spriteRenderer.sortingOrder; } return(unit); case Unit.ResultOnAction.FAILED: cancelUnit(); if (prevUnit) { ++prevUnit.spriteRenderer.sortingOrder; } return(null); case Unit.ResultOnAction.CANCELED: case Unit.ResultOnAction.NOACTION: actions.RemoveAt(actions.Count - 1); if (result == Unit.ResultOnAction.NOACTION || (!prevUnit && R.input.click == thisPos)) { if (await Play(actions, buyAction)) { unit.isSleep = true; goto case Unit.ResultOnAction.SUCCESSFULED; } goto case Unit.ResultOnAction.FAILED; } break; } } }