예제 #1
0
        /// <summary>
        /// TradeTable
        /// </summary>
        /// <param name="TradeTable">TradeTable实体对象</param>
        /// <returns>状态代码</returns>
        public int Update(TradeTable obj)
        {
            try
            {
                string sql = "UPDATE Trades set PlatformID=@PlatformID,OrderTxid=@OrderTxid, TransactionID=@TransactionID, Executed=@Executed,Status=@Status,AvgPrice=@AvgPrice,Volume=@Volume,Cost=@Cost," +
                             "Fee=@Fee,LastChangeTime=datetime('now', 'localtime') where id=@ID";

                using (SQLiteCommand cmd = new SQLiteCommand(sql))
                {
                    cmd.Parameters.AddWithValue("@ID", obj.ID);
                    cmd.Parameters.AddWithValue("@PlatformID", obj.Platform.ID);
                    cmd.Parameters.AddWithValue("@TransactionID", obj.TransactionID);
                    cmd.Parameters.AddWithValue("@Executed", obj.Executed);
                    cmd.Parameters.AddWithValue("@OrderTxid", obj.OrderTxid);
                    cmd.Parameters.AddWithValue("@Status", obj.Status);
                    cmd.Parameters.AddWithValue("@AvgPrice", obj.AvgPrice);
                    cmd.Parameters.AddWithValue("@Volume", obj.Volume);
                    cmd.Parameters.AddWithValue("@Cost", obj.Cost);
                    cmd.Parameters.AddWithValue("@Fee", obj.Fee);

                    return(SQLiteHelper.SQLiteHelper.ExecuteNonQuery(conStr, cmd));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("调用TradeTable 时,访问Update时出错", ex);
            }
        }
예제 #2
0
        /// <summary>
        ///  TradeTable
        /// </summary>
        /// <param name="TradeTable">TradeTable实体对象</param>
        public void Insert(TradeTable obj)
        {
            try
            {
                string sql = "insert into Trades(TransactionID,Executed, PlatformID,OrderTxid,Status,AvgPrice,Volume,Cost,Fee,CreateTime,LastChangeTime) " +
                             "values(@TransactionID,@Executed, @PlatformID,@OrderTxid,@Status,@AvgPrice,@Volume,@Cost,@Fee,datetime('now', 'localtime'),datetime('now', 'localtime'))";

                using (SQLiteCommand cmd = new SQLiteCommand(sql))
                {
                    cmd.Parameters.AddWithValue("@PlatformID", obj.Platform.ID);
                    cmd.Parameters.AddWithValue("@TransactionID", obj.TransactionID);
                    cmd.Parameters.AddWithValue("@Executed", obj.Executed);
                    cmd.Parameters.AddWithValue("@OrderTxid", obj.OrderTxid);
                    cmd.Parameters.AddWithValue("@Status", obj.Status);
                    cmd.Parameters.AddWithValue("@AvgPrice", obj.AvgPrice);
                    cmd.Parameters.AddWithValue("@Volume", obj.Volume);
                    cmd.Parameters.AddWithValue("@Cost", obj.Cost);
                    cmd.Parameters.AddWithValue("@Fee", obj.Fee);

                    SQLiteHelper.SQLiteHelper.ExecuteNonQuery(conStr, cmd);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("调用TradeTable时,访问Insert时出错", ex);
            }
        }
예제 #3
0
        /// <summary>
        /// TradeTable
        /// </summary>
        /// <param name="TradeTable">TradeTable实体对象</param>
        /// <returns>状态代码</returns>
        public int Delete(TradeTable obj)
        {
            try
            {
                string sql = "delete from Trades where id=@ID";

                using (SQLiteCommand cmd = new SQLiteCommand(sql))
                {
                    cmd.Parameters.AddWithValue("@ID", obj.ID);

                    return(SQLiteHelper.SQLiteHelper.ExecuteNonQuery(conStr, cmd));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("调用TradeTable 时,访问Delete时出错", ex);
            }
        }
예제 #4
0
    // Use this for initialization
    void Start()
    {
        Debug.logger.logEnabled = false;
        lastTick = 0;
        int count = 0;
        var com   = Commodities.Instance.com;

        gMeanPrice      = new List <GraphMe>(com.Count);
        gUnitsExchanged = new List <GraphMe>(com.Count);
        gProfessions    = new List <GraphMe>(com.Count);

        /* initialize graphs */
        var gmp = GameObject.Find("AvgPriceGraph");

        for (int i = 0; i < com.Count; i++)
        {
            gMeanPrice.Add(gmp.transform.Find("line" + i).GetComponent <GraphMe>());
        }
        var gue = GameObject.Find("UnitsExchangedGraph");

        for (int i = 0; i < com.Count; i++)
        {
            gUnitsExchanged.Add(gue.transform.Find("line" + i).GetComponent <GraphMe>());
        }
        var gp = GameObject.Find("ProfessionsGraph");

        for (int i = 0; i < com.Count; i++)
        {
            gProfessions.Add(gp.transform.Find("line" + i).GetComponent <GraphMe>());
        }

        var prefab = Resources.Load("Agent");

        for (int i = transform.childCount; i < numAgents; i++)
        {
            GameObject go = Instantiate(prefab) as GameObject;
            go.transform.parent = transform;
            go.name             = "agent" + i.ToString();
        }
        /* initialize agents */
        foreach (Transform tChild in transform)
        {
            GameObject child = tChild.gameObject;
            var        agent = child.GetComponent <EconAgent>();

            string type       = "invalid";
            int    numPerType = transform.childCount / 5;
            int    typeNum    = 1;
            if (count < numPerType * typeNum++)
            {
                type = "Food";                                                          //farmer
            }
            else if (count < numPerType * typeNum++)
            {
                type = "Wood";                                                  //woodcutter
            }
            else if (count < numPerType * typeNum++)
            {
                type = "Ore";                                                   //miner
            }
            else if (count < numPerType * typeNum++)
            {
                type = "Metal";                                                 //refiner
            }
            else if (count < numPerType * typeNum)
            {
                type = "Tool";                                                  //blacksmith
            }
            else
            {
                Debug.Log(count + " too many agents, not supported: " + typeNum);
            }
            InitAgent(agent, type);
            agents.Add(agent);
            count++;
        }
        askTable = new TradeTable();
        bidTable = new TradeTable();

        //initialize agents
    }
예제 #5
0
        public bool ReloadOrder()
        {
            var account = new AccountDao().Select()
                          .Find(a => a.Default > 0 || a.Platform.ID == platform.ID);
            string uid = account.UID;

            var dao      = new OrderDao();
            var tradeDao = new TradeDao();
            var orders   = new List <OrderTable>();
            var trads    = new List <TradeTable>();

            string end   = dao.SelectTxid();
            var    depth = client.GetClosedOrders(true, "", "", end);

            var res = depth["result"] as JsonObject;

            if (res != null)
            {
                var os = res["closed"] as JsonObject;

                foreach (var item in os)
                {
                    JsonObject jOrder = item.Value as JsonObject;
                    JsonObject jDescr = jOrder["descr"] as JsonObject;

                    string pair       = jDescr["pair"].ToString();
                    int    spiltIndex = (int)Math.Ceiling((double)pair.Length / 2);
                    string coin       = pair.Substring(0, spiltIndex);
                    string currency   = pair.Substring(spiltIndex, pair.Length - spiltIndex);

                    var order = new OrderTable()
                    {
                        OrderTxid  = item.Name,
                        UID        = uid,
                        Opened     = UnixTimeStampToDateTime(double.Parse(jOrder["opentm"].ToString())),
                        Closed     = UnixTimeStampToDateTime(double.Parse(jOrder["closetm"].ToString())),
                        Status     = jOrder["status"].ToString(),
                        Volume     = double.Parse(jOrder["vol"].ToString()),
                        Price      = double.Parse(jOrder["price"].ToString()),
                        LimitPrice = double.Parse(jOrder["limitprice"].ToString()),

                        Type           = jDescr["type"].ToString(),
                        LimitType      = jDescr["ordertype"].ToString(),
                        Coin           = coin,
                        Currency       = currency,
                        Pair           = pair,
                        CreateTime     = DateTime.Now,
                        LastChangeTime = DateTime.Now,
                        Platform       = this.platform
                    };

                    var jtrads = jOrder["trades"] as JsonArray;
                    foreach (var jtrad in jtrads)
                    {
                        var trad = new TradeTable()
                        {
                            TransactionID  = jtrad.ToString(),
                            OrderTxid      = item.Name,
                            CreateTime     = DateTime.Now,
                            LastChangeTime = DateTime.Now,
                            Platform       = this.platform
                        };

                        trads.Add(trad);
                    }

                    orders.Add(order);
                }

                dao.InsertOrUpdate(orders);
                tradeDao.InsertOrUpdate(trads);
            }
            return(true);
        }
예제 #6
0
    void Update()
    {
        switch (state)
        {
        case BrainStates.Browsing:

            break;

        case BrainStates.Lingering:

            lingerTimer += Time.deltaTime;

            //Debug.Log(CurrentStation);

            if (CurrentStation != null && lingerTimer <= lingerTime)
            {
                RotateTowards(CurrentStation.transform);

                if (currentStation.GetType() == typeof(ItemDisplay))
                {
                    ItemDisplay display = (ItemDisplay)currentStation;

                    if (display.displayedItem != null)
                    {
                        for (int i = 0; i < wantedItems.Count; i++)
                        {
                            if (wantedItems[i] == display.displayedItem.itemCode)
                            {
                                hero.PickupItem(currentStation.Interact());
                                lingerTimer = 0f;
                                ChoosePointOfInterest(POIType.Trade);

                                return;
                            }
                        }
                    }
                }
            }

            if (lingerTimer >= lingerTime)
            {
                lingerTimer = 0f;
                if (Random.Range(1, 11) == 1)
                {
                    ChoosePointOfInterest(POIType.Door);
                }
                else
                {
                    ChoosePointOfInterest(POIType.Item);
                }
            }

            break;

        case BrainStates.Moving:
            if (Vector3.Distance(transform.position, agent.destination) <= 1.1f)
            {
                switch (currentPOI.navPointOfInterest)
                {
                case POIType.Door:
                    state = BrainStates.Exiting;
                    break;

                case POIType.Item:
                    state      = BrainStates.Lingering;
                    lingerTime = Random.Range(1f, 5f);
                    break;

                case POIType.Trade:
                    state = BrainStates.WaitingToTrade;
                    break;
                }
            }
            break;

        case BrainStates.WaitingToTrade:

            //Debug.Log(string.Format("{0} | {1} | {2} ", currentStation, currentStation.GetType(), currentTrade == null));

            if (currentStation != null && currentStation.GetType() == typeof(TradeTable) && currentTrade == null)
            {
                TradeTable table = (TradeTable)currentStation;
                //TODO: create actual gold offer logic
                currentTrade = table.CreateTrade(hero.carriedItem, 2, hero);
            }
            break;

        case BrainStates.Exiting:
            ExitShop();
            break;

        case BrainStates.Questing:
            hero.currentQuest.RunQuest();

            //For now just remove the quest
            //TODO: hold on to quest to tell player about?
            EnterShop();
            break;
        }
    }