Beispiel #1
0
 public static void Serialize(uLink.BitStream stream, object value, params object[] codecOptions)
 {
     try
     {
         TownTradeItemInfo ttii = value as TownTradeItemInfo;
         stream.WriteInt32(ttii.pos.x);
         stream.WriteInt32(ttii.pos.y);
         stream.WriteInt32(ttii.csti.id);
         stream.WriteSingle(ttii.m_CurTime);
         stream.WriteSingle(ttii.m_Time);
         stream.WriteInt32(ttii.needItems.Count);
         foreach (TradeObj to in ttii.needItems)
         {
             TradeObj.Serialize(stream, to);
         }
         stream.WriteInt32(ttii.rewardItems.Count);
         foreach (TradeObj to in ttii.rewardItems)
         {
             TradeObj.Serialize(stream, to);
         }
     }
     catch (System.Exception e)
     {
         throw e;
     }
 }
Beispiel #2
0
 public static object Deserialize(uLink.BitStream stream, params object[] codecOptions)
 {
     try
     {
         IntVector2        pos  = new IntVector2(stream.ReadInt32(), stream.ReadInt32());
         TownTradeItemInfo ttii = new TownTradeItemInfo(pos);
         ttii.csti      = CSTradeInfoData.GetData(stream.ReadInt32());
         ttii.m_CurTime = stream.ReadSingle();
         ttii.m_Time    = stream.ReadSingle();
         int needItemsCount = stream.ReadInt32();
         for (int m = 0; m < needItemsCount; m++)
         {
             ttii.needItems.Add((TradeObj)TradeObj.Deserialize(stream));
         }
         int rewardItemsCount = stream.ReadInt32();
         for (int m = 0; m < rewardItemsCount; m++)
         {
             ttii.rewardItems.Add((TradeObj)TradeObj.Deserialize(stream));
         }
         return(ttii);
     }
     catch (System.Exception e)
     {
         throw e;
     }
 }
Beispiel #3
0
    public void setRewardNum(int protoId, int num)
    {
        TradeObj to = rewardItems.Find(it => it.protoId == protoId);

        if (to != null)
        {
            to.count = Mathf.Min(num, to.max);
        }
    }
Beispiel #4
0
 public static void Serialize(uLink.BitStream stream, object value, params object[] codecOptions)
 {
     try
     {
         TradeObj to = value as TradeObj;
         stream.WriteInt32(to.protoId);
         stream.WriteInt32(to.count);
         stream.WriteInt32(to.max);
     }
     catch (System.Exception e)
     {
         throw e;
     }
 }
Beispiel #5
0
 public static object Deserialize(uLink.BitStream stream, params object[] codecOptions)
 {
     try
     {
         int      protoId = stream.ReadInt32();
         int      count   = stream.ReadInt32();
         int      max     = stream.ReadInt32();
         TradeObj to      = new TradeObj(protoId, count, max);
         return(to);
     }
     catch (System.Exception e)
     {
         throw e;
     }
 }
Beispiel #6
0
 public void DoTrade(ICollection <TradeObj> need)
 {
     foreach (TradeObj to in need)
     {
         TradeObj ttiiTo = needItems.Find(it => it.protoId == to.protoId);
         if (ttiiTo != null)
         {
             ttiiTo.count -= to.count;
             if (ttiiTo.count < 0)
             {
                 ttiiTo.count = 0;
             }
         }
     }
 }
Beispiel #7
0
    public static void LoadData()
    {
        SqliteDataReader reader = LocalDatabase.Instance.ReadFullTable("tradePost");

        while (reader.Read())
        {
            CSTradeInfoData cstid = new CSTradeInfoData();
            cstid.id = Convert.ToInt32(reader.GetString(reader.GetOrdinal("tradeID")));
            string[] needitems = reader.GetString(reader.GetOrdinal("need")).Split(';');
            foreach (string item in needitems)
            {
                string[] protoIdNumStr = item.Split(',');
                TradeObj pob           = new TradeObj(Convert.ToInt32(protoIdNumStr[0]), Convert.ToInt32(protoIdNumStr[1]));
                cstid.needItemList.Add(pob);
            }
            string[] typeAmount1 = reader.GetString(reader.GetOrdinal("typeAmount1")).Split(',');
            cstid.needTypeAmountMin = Convert.ToInt32(typeAmount1[0]);
            cstid.needTypeAmountMax = Convert.ToInt32(typeAmount1[1]);
            cstid.needRandomVariate = reader.GetFloat(reader.GetOrdinal("randomMax"));
            string[] rewarditems = reader.GetString(reader.GetOrdinal("reward")).Split(';');
            foreach (string item in rewarditems)
            {
                string[] protoIdNumStr = item.Split(',');
                TradeObj pob           = new TradeObj(Convert.ToInt32(protoIdNumStr[0]), Convert.ToInt32(protoIdNumStr[1]));
                cstid.rewardItemList.Add(pob);
            }
            string[] typeAmount2 = reader.GetString(reader.GetOrdinal("typeAmount2")).Split(',');
            cstid.rewardTypeAmountMin = Convert.ToInt32(typeAmount2[0]);
            cstid.rewardTypeAmountMax = Convert.ToInt32(typeAmount2[1]);
            cstid.refreshTime         = Convert.ToSingle(reader.GetString(reader.GetOrdinal("refreshTime")));
            if (Application.isEditor)
            {
                cstid.refreshTime = 40;
            }
            cstid.icon = reader.GetString(reader.GetOrdinal("icon"));
            cstid.CheckData();
            mTradeInfo.Add(cstid.id, cstid);
        }
    }