Exemple #1
0
        /********************************************
        ****** METHODES SPECIFIQUES AU WIDGET ******
        ********************************************/


        /// <summary>
        /// base menu constructor
        /// </summary>
        public TeamSelection() : base(new Rect(0, 0, Screen.width * DIM_WIDTH, Screen.height * DIM_HEIGHT))
        {
            this.Background = BACKGROUND_COLOR;
            team_selector   = new Selector(new Rect(this.area.width * (1 - DIM_SELECTOR_WIDTH) / 2, (this.area.height - 2 * DIM_SELECTOR_HEIGHT) / 3, DIM_SELECTOR_WIDTH * this.area.width, DIM_SELECTOR_HEIGHT), (int)(DIM_SELECTOR_DROP_HEIGHT_1 * this.area.height), this);
            unit_selector   = new Selector(new Rect(this.area.width * (1 - DIM_SELECTOR_WIDTH) / 2, (this.area.height - 2 * DIM_SELECTOR_HEIGHT) * 2 / 3 + DIM_SELECTOR_HEIGHT, DIM_SELECTOR_WIDTH * this.area.width, DIM_SELECTOR_HEIGHT), (int)(DIM_SELECTOR_DROP_HEIGHT_2 * this.area.height), this);

            this.AddChild(unit_selector);
            this.AddChild(team_selector);
            team_selector.SelectItem   += OnSelectItem;
            team_selector.DeployOrTuck += OnDeployOrTuck;
            unit_selector.SelectItem   += OnSelectItem;

            XMLInterpreter interpreter = new XMLInterpreter();

            // A SUPPRIMER
            team_selector.Elements = interpreter.allTeamsInXmlFiles(Constants.teamsDirectory).ToArray();

            List <string> units = new List <string> ();

            foreach (BotType t in BotType.GetValues(typeof(BotType)))
            {
                units.Add(BotTypes.WarType(t));
            }

            unit_selector.Elements = units.ToArray();
        }
Exemple #2
0
        public static IBot CreateBot(BotTypes type, int id, string code = null)
        {
            switch (type)
            {
            case BotTypes.Builtin:
                return(BuiltinBotFactory.GetBot(id, code));

            case BotTypes.Javascript:
                return(new JsBot(id, code));
            }

            throw new ArgumentOutOfRangeException(nameof(type));
        }
Exemple #3
0
        /// <summary>
        /// Reload this instance.
        /// </summary>
        public void Reload()
        {
            XMLInterpreter interpreter = new XMLInterpreter();

            team_selector.Elements = interpreter.allTeamsInXmlFiles(Constants.teamsDirectory).ToArray();

            List <string> units = new List <string>();

            foreach (BotType t in BotType.GetValues(typeof(BotType)))
            {
                units.Add(BotTypes.WarType(t));
            }

            unit_selector.Elements = units.ToArray();
            if (team_selector.Elements.Length > 0)
            {
                GameObject.Find("Button_Return").GetComponent <UnityEngine.UI.Button>().interactable = true;
            }
        }
Exemple #4
0
        void OnMsg(string msg, BotTypes botType)
        {
            if (MessageHandler != null)
            {
                MessageHandler(this, msg);
            }
            var dis = dispatches[botType];

            if (dis == null)
            {
                return;
            }
            var msgqu = MessageQueues[botType];

            if (msgqu == null)
            {
                return;
            }
            dis.Invoke(() => { msgqu.Enqueue(string.Format("{0}: {1}", DateTime.Now, msg)); });
        }
Exemple #5
0
        private void update_level1_links(List <XListing> listings, BotTypes botType, string recordId, FreeTask tsk)
        {
            if (listings == null || listings.Count == 0)
            {
                log("SUCCESS update 0 apps Links for " + tsk.TaskName);
                return;
            }
            var itemdt = GetItemList(listings);

            for (int i = 0; i < itemdt.Count; i++)
            {
                var update = new UpdateDocument {
                    { "$set", new QueryDocument {
                          { "PageNum", itemdt[i].PageNum }, { "TotalComments", itemdt[i].TotalComments }, { "Price", itemdt[i].Price },
                          { "Recent30DaysSoldNum", itemdt[i].Recent30DaysSoldNum }, { "Position", itemdt[i].Position }
                      } }
                };
                var result = MongoDBHelper.Instance.Get_FreeBotItem().UpdateOne(new QueryDocument {
                    { "ItemId", itemdt[i].ItemId }
                }, update);
            }
        }
Exemple #6
0
        static public BotBase FabricateBot(IMyCubeGrid Grid, IMyRemoteControl RC)
        {
            try
            {
                BotTypes BotType = BotBase.ReadBotType(RC);

                BotBase Bot = null;
                switch (BotType)
                {
                case BotTypes.Fighter:
                    Bot = new FighterBot(Grid);
                    break;

                case BotTypes.Freighter:
                    Bot = new FreighterBot(Grid);
                    break;

                case BotTypes.Station:
                    Bot = new StationBot(Grid);
                    break;

                default:
                    if (AISessionCore.AllowThrowingErrors)
                    {
                        throw new Exception("Invalid bot type");
                    }
                    break;
                }

                return(Bot);
            }
            catch (Exception Scrap)
            {
                Grid.LogError("BotFabric.FabricateBot", Scrap);
                return(null);
            }
        }
Exemple #7
0
        void SaveResult(List <XListing> listings, BotTypes botType, string recordId, FreeTask tsk)
        {
            listings.ToList().ForEach(x =>
            {
                if (string.IsNullOrEmpty(x.ShopName) && !string.IsNullOrEmpty(x.SiteName) && !x.BotShopID.HasValue &&
                    !x.SiteName.ToLower().Contains("taobao") && !x.SiteName.ToLower().Contains("alibaba"))
                {
                    x.ShopName  = x.SiteName;
                    x.BotShopID = x.SiteID;
                }
                if (!x.BotShopID.HasValue && !string.IsNullOrEmpty(x.ShopName))
                {
                    x.BotShopID = IDHelper.GetGuid(string.Format("{0},{1},{2},{3}", x.ShopName, x.SiteName, tsk._id, x.ShopID));
                }
            });
            var shopList = listings;

            shopList = shopList.DistinctBy(x => x.BotShopID);
            //var exists_ids = MySqlDbHelper.GetExsitsIds<Guid?>(com, "bot_shops", "Shop_id", shopList.Select(x => x.BotShopID).ToArray());
            //if (exists_ids != null && exists_ids.Count > 0)
            //{
            //    shopList = shopList.Where(x => !exists_ids.Contains(x.BotShopID)).ToList();
            //}

            FieldsDocument shopfd = new FieldsDocument();

            shopfd.Add("BotShopID", 1);
            // MongoCollection<Guid> shopcol = MongoDBHelper<Guid>.GetMongoDB().GetCollection<Guid>("FreeBotShop");
            var shopcol = MongoDBHelper.Instance.Get_FreeBotShop();
            var builder = Builders <FreeBotShop> .Filter;

            List <Guid?> BotShopID = shopList.Select(x => x.BotShopID).ToList();
            //  var existsshop_objs = shopcol.Find(MongoDB.Driver.Builders.Query.In("BotShopID", new BsonArray(BotShopID))).SetFields(shopfd);
            var          existsshop_objs = shopcol.Find(builder.In(x => x.Shop_id, BotShopID)).Project(x => x.Shop_id).ToList();
            List <Guid?> exists_ids      = new List <Guid?>();

            foreach (var result in existsshop_objs)
            {
                exists_ids.Add(result);
            }
            if (exists_ids != null && exists_ids.Count > 0)
            {
                shopList = shopList.Where(x => !exists_ids.Contains(x.BotShopID)).ToList();
            }
            if (shopList == null || shopList.Count == 0)
            {
                return;
            }
            List <FreeBotShop> dt = null;

            if (shopList.Count > 0)
            {
                dt = GetShopList(shopList);
                //  var saved = MongoDBHelper<FreeBotShop>.BatchInsertData(dt, "FreeBotShop");
                shopcol.InsertMany(dt);
                log("to save bot_shops");
                log("Done");
            }
            listings.ToList().ForEach(x =>
            {
                if (!x.BotItemID.HasValue && !string.IsNullOrEmpty(x.ItemName))
                {
                    x.BotItemID = IDHelper.GetGuid(string.Format("{0},{1},{2},{3}", x.ItemName, x.SiteName, tsk._id, x.ItemID));
                }
            });
            var itemList = listings;

            itemList = itemList.DistinctBy(x => x.BotItemID);
            //var exists_itemids = MySqlDbHelper.GetExsitsIds<Guid?>(com, "bot_items", "ItemId", itemList.Select(x => x.BotItemID).ToArray());
            //if (exists_itemids != null && exists_itemids.Count > 0)
            //{
            //    itemList = itemList.Where(x => !exists_itemids.Contains(x.BotItemID)).ToList();
            //}

            FieldsDocument fd = new FieldsDocument();

            fd.Add("BotItemID", 1);
            //   MongoCollection<Guid> col = MongoDBHelper<Guid>.GetMongoDB().GetCollection<Guid>("FreeBotItem");
            var          col         = MongoDBHelper.Instance.Get_FreeBotItem();
            var          itemBuilder = Builders <FreeBotItem> .Filter;
            List <Guid?> BotItemID   = itemList.Select(x => x.BotItemID).ToList();
            //  var exists_objs = col.Find(MongoDB.Driver.Builders.Query.In("BotItemID", new BsonArray(BotItemID))).SetFields(fd);
            var          exists_objs    = col.Find(itemBuilder.In(x => x.ItemId, BotItemID)).Project(x => x.ItemId).ToList();
            List <Guid?> existsitem_ids = new List <Guid?>();

            foreach (var result in exists_objs)
            {
                existsitem_ids.Add(result);
            }
            if (existsitem_ids != null && existsitem_ids.Count > 0)
            {
                itemList = itemList.Where(x => !existsitem_ids.Contains(x.BotItemID)).ToList();
            }

            List <XListing> updatelinks = new List <XListing>();

            if (existsitem_ids != null && existsitem_ids.Count > 0)
            {
                updatelinks = updatelinks.Where(x => existsitem_ids.Contains(x.BotItemID)).ToList();
            }
            update_level1_links(updatelinks, botType, recordId, tsk);
            if (itemList == null || itemList.Count == 0)
            {
                return;
            }

            var itemdt = GetItemList(itemList);

            //  var savedListings = MySqlDbHelper.BatchInsert(con, "bot_items", itemdt);
            // var savedListings = MongoDBHelper<FreeBotItem>.BatchInsertData(itemdt, "FreeBotItem");
            col.InsertMany(itemdt);

            // var wequery = new QueryDocument { { "_id", new ObjectId(recordId) } };
            // FreeTaskRecord TaskList = MongoDBHelper<FreeTaskRecord>.Find1("FreeTaskRecord", wequery);
            var            colRecord     = MongoDBHelper.Instance.Get_FreeTaskRecord();
            var            RecordBuilder = Builders <FreeTaskRecord> .Filter;
            FreeTaskRecord TaskList      = colRecord.Find(RecordBuilder.Eq(x => x._id, new ObjectId(recordId))).FirstOrDefault();
            int            LinksNum      = 0;
            int            ShopsNum      = 0;

            LinksNum = TaskList.LinksNum + itemdt.Count;
            ShopsNum = TaskList.ShopsNum + dt.Count;
            var updateWebsiteCount = new UpdateDocument {
                { "$set", new QueryDocument {
                      { "LinksNum", LinksNum }, { "ShopsNum", ShopsNum }
                  } }
            };

            //  MongoDBHelper<FreeTaskRecord>.Update("FreeTaskRecord", wequery, updateWebsiteCount);
            MongoDBHelper.Instance.Get_FreeTaskRecord().UpdateOne(new QueryDocument {
                { "_id", new ObjectId(recordId) }
            }, updateWebsiteCount);


            var      colTask      = MongoDBHelper.Instance.Get_FreeTask();
            var      TaskBuilder  = Builders <FreeTask> .Filter;
            FreeTask Task2List    = colTask.Find(TaskBuilder.Eq(x => x._id, itemdt[0].taskId)).FirstOrDefault();
            int      TaskLinksNum = 0;
            int      TaskShopsNum = 0;

            TaskLinksNum = Task2List.LinksNum + itemdt.Count;
            TaskShopsNum = Task2List.ShopsNum + dt.Count;
            var TaskupdateWebsiteCount = new UpdateDocument {
                { "$set", new QueryDocument {
                      { "LinksNum", TaskLinksNum }, { "ShopsNum", TaskShopsNum }
                  } }
            };

            //  MongoDBHelper<FreeTaskRecord>.Update("FreeTaskRecord", wequery, updateWebsiteCount);
            MongoDBHelper.Instance.Get_FreeTask().UpdateOne(new QueryDocument {
                { "_id", itemdt[0].taskId }
            }, TaskupdateWebsiteCount);

            log("to save listings");
            log("Done");
        }
Exemple #8
0
        static public BotTypes ReadBotType(IMyRemoteControl RC)
        {
            try
            {
                string        _CustomData = RC.CustomData.Trim().Replace("\r\n", "\n");
                List <string> CustomData  = new List <string>(_CustomData.Split('\n'));

                if (_CustomData.IsNullEmptyOrWhiteSpace())
                {
                    return(BotTypes.None);
                }
                if (CustomData.Count < 2)
                {
                    if (AISessionCore.AllowThrowingErrors)
                    {
                        throw new Exception("CustomData is invalid", new Exception("CustomData consists of less than two lines"));
                    }
                    else
                    {
                        return(BotTypes.Invalid);
                    }
                }
                if (CustomData[0].Trim() != "[EEM_AI]")
                {
                    if (AISessionCore.AllowThrowingErrors)
                    {
                        throw new Exception("CustomData is invalid", new Exception($"AI tag invalid: '{CustomData[0]}'"));
                    }
                    return(BotTypes.Invalid);
                }

                string[] bottype = CustomData[1].Split(':');
                if (bottype[0].Trim() != "Type")
                {
                    if (AISessionCore.AllowThrowingErrors)
                    {
                        throw new Exception("CustomData is invalid", new Exception($"Type tag invalid: '{bottype[0]}'"));
                    }
                    return(BotTypes.Invalid);
                }

                BotTypes BotType = BotTypes.Invalid;
                switch (bottype[1].Trim())
                {
                case "Fighter":
                    BotType = BotTypes.Fighter;
                    break;

                case "Freighter":
                    BotType = BotTypes.Freighter;
                    break;

                case "Carrier":
                    BotType = BotTypes.Carrier;
                    break;

                case "Station":
                    BotType = BotTypes.Station;
                    break;
                }

                return(BotType);
            }
            catch (Exception Scrap)
            {
                RC.CubeGrid.LogError("[STATIC]BotBase.ReadBotType", Scrap);
                return(BotTypes.Invalid);
            }
        }
Exemple #9
0
        public void InitAI()
        {
            if (!AISessionCore.IsServer)
            {
                return;
            }
            SetupRecompileTimer();

            try
            {
                if (Grid.Physics == null || (Grid as MyEntity).IsPreview)
                {
                    return;
                }
            }
            catch (Exception Scrap)
            {
                LogError("InitAI[grid check]", Scrap);
            }

            try
            {
                if (string.IsNullOrWhiteSpace(RC.CustomData) || !RC.CustomData.Contains("[EEM_AI]"))
                {
                    Shutdown(Notify: false);
                    return;
                }

                //DebugWrite("GridComponent.InitAI", "Booting up RC component.");

                if (!RC.IsOwnedByNPC())
                {
                    DebugWrite("GridComponent.InitAI", "RC is not owned by NPC!");
                    Shutdown(Notify: false);
                    return;
                }

                if (RC.CustomData.Contains("Faction:"))
                {
                    try
                    {
                        TryAssignToFaction();
                    }
                    catch (Exception Scrap)
                    {
                        LogError("TryAssignToFaction", Scrap);
                    }
                }

                if (RC.CustomData.Contains("Type:None"))
                {
                    IsOperable = true;
                    Inited     = true;
                    DebugWrite("GridComponent.InitAI", "Type:None, shutting down.");
                    Shutdown(Notify: false);
                    return;
                }

                BotTypes BotType = BotBase.ReadBotType(RC);
                if (BotType == BotTypes.None)
                {
                    DebugWrite("GridComponent.InitAI", "Skipping grid — no setup found");
                }
                else if (BotType == BotTypes.Invalid)
                {
                    LogError("GridComponent.InitAI", new Exception("Bot type is not valid!", new Exception()));
                }

                //DebugWrite("GridComponent.InitAI", $"Bot found. Bot type: {BotType.ToString()}");
            }
            catch (Exception Scrap)
            {
                LogError("GridComponent.InitAI", Scrap);
                return;
            }

            try
            {
                AI = BotFabric.FabricateBot(Grid, RC);

                if (AI == null)
                {
                    DebugWrite("GridComponent.InitAI", "Bot Fabricator yielded null");
                    Shutdown();
                    return;
                }

                bool init = AI.Init(RC);

                if (init)
                {
                    //DebugWrite("GridComponent.InitAI", "AI.Init() successfully initialized AI component");
                }
                else
                {
                    DebugWrite("GridComponent.InitAI", "AI.Init() returned false — bot initialization failed somewhy");
                    Shutdown();
                    return;
                }

                //DebugWrite("GridComponent.InitAI", $"AI Operable: {AI.Operable}");

                if (AI.Update != default(MyEntityUpdateEnum))
                {
                    RC.NeedsUpdate |= AI.Update;
                }
                RC.OnMarkForClose += (trash) => { Shutdown(); };
                IsOperable         = true;
                Inited             = true;
                //Grid.DebugWrite("InitAI", "Grid Component successfully inited.");
            }
            catch (Exception Scrap)
            {
                LogError("GridComponent.InitAI", Scrap);
                Shutdown();
            }
        }