Exemplo n.º 1
0
        State OnCheckState()
        {
            passedTime = System.TimeSpan.Zero;
            bool isUnhold;
            var  allDishes = runtimeData.GetList <DBCraftingItem>()
                             .Where(x => x.tableUID == runtimeTable.uid)
                             .OrderBy(x => x.insertedTime)
                             .ToList();

            currentMaking = FIShareCraftFunc.GetCurrentCookingRecipe(
                easy.GlobalInfo.totalCraftedCompleteCnt,
                easy.ServerTime - runtimeTable.recipeStartedTime,
                allDishes,
                out passedTime,
                out isUnhold);
            if (currentMaking == null)
            {
                return(State.Empty);
            }
            if (isUnhold == true)
            {
                return(State.Unhold);
            }
            return(State.Making);
        }
Exemplo n.º 2
0
    public static JObject enc_sess_craft_collect(FIFakeContext context)
    {
        CheckParameterExists(context, "uidArr");
        var uidArr     = context.body["uidArr"].Values <int>().ToArray();
        var recipeList = context.dbContext.GetList <DBCraftingItem>()
                         .Where(x => uidArr.Contains(x.uid))
                         .ToList();

        //Check
        #region Check if requesting recipe actually exists..
        if (recipeList.Count <= 0)
        {
            throw new FIException(FIErr.Crafting_CollectThereIsNoRecipeMatch);
        }
        #endregion
        #region Check if its from same table..
        int singleUID = -1;
        foreach (var item in recipeList)
        {
            if (singleUID == -1)
            {
                singleUID = item.tableUID;
                continue;
            }
            if (singleUID != item.tableUID)
            {
                throw new FIException(FIErr.Crafting_CollectingNotMatchTableUID);
            }
        }
        #endregion
        #region Check requesting is all completed..
        var runtimeTable      = context.dbContext.GetByID <DBCraftingTable>(singleUID);
        var staticTable       = context.staticData.GetByID <GDCraftingTable>(runtimeTable.craftingTableID);
        var currentRecipeList = context.dbContext.GetList <DBCraftingItem>()
                                .Where(x => x.tableUID == runtimeTable.uid)
                                .OrderBy(x => x.insertedTime)
                                .ToList();
        int  completeQueueSize   = context.easy.GlobalInfo.totalCraftedCompleteCnt;
        var  curServerTime       = CurrentTime;
        var  estimateStartedTime = runtimeTable.recipeStartedTime;
        var  passedTime          = curServerTime - estimateStartedTime;
        bool isUnhold            = false;
        var  currentMakingItem   = FIShareCraftFunc.GetCurrentCookingRecipe(completeQueueSize, passedTime, currentRecipeList, out isUnhold);
        var  madeList            = FIShareCraftFunc.GetMadeDishList(completeQueueSize, passedTime, currentRecipeList);
        foreach (var item in recipeList)
        {
            Debug.Log("ReqItem=" + item.uid + " reqTime=" + item.reqTime);
        }
        foreach (var item in madeList)
        {
            Debug.Log("MadeItem=" + item.uid + " reqTime=" + item.reqTime);
        }
        foreach (var item in recipeList)
        {
            if (madeList.Contains(item) == false)
            {
                throw new FIException(FIErr.Crafting_CollectingNotCompletedOne);
            }
        }
        #endregion
        #region Check I can insert reward.
        Dictionary <int, int> totalRewardDic = new Dictionary <int, int>();
        foreach (var item in recipeList)
        {
            var staticSingle = context.staticData.GetByID <GDCraftRecipeData>(item.recipeID);
            foreach (var single in staticSingle.rewardArr)
            {
                if (totalRewardDic.ContainsKey(single.item.id) == false)
                {
                    totalRewardDic.Add(single.item.id, single.cnt);
                }
                else
                {
                    totalRewardDic[single.item.id] += single.cnt;
                }
            }
        }
        var totalRewardArr = totalRewardDic.Select(x => Tuple.Create <int, int>(x.Key, x.Value)).ToArray();
        if (Storage_CheckCanInsertItems(context, totalRewardArr) == false)
        {
            throw new FIException(FIErr.Crafting_CollectingCannotInsertRewards);
        }
        #endregion

        //Action
        #region Reset time of table started!
        if (isUnhold == true || currentMakingItem == null)
        {
            var onlyLeftItemList = madeList
                                   .Where(x => recipeList.Contains(x) == false)
                                   .ToList();
            var totalTime = System.TimeSpan.Zero;
            //Should calculate the only left things..
            foreach (var item in onlyLeftItemList)
            {
                totalTime += item.reqTime;
            }
            runtimeTable.recipeStartedTime = curServerTime - totalTime;
            InsertUpdated(context, runtimeTable);
        }
        else
        {
            var totalTime = System.TimeSpan.Zero;
            foreach (var item in recipeList)
            {
                // totalTime
                totalTime += item.reqTime;
            }
            runtimeTable.recipeStartedTime += totalTime;
            InsertUpdated(context, runtimeTable);
        }
        #endregion
        #region RemoveRecipies from list
        InsertDeleted(context, recipeList.ToArray());
        context.dbContext.Dispose(recipeList.ToArray());
        #endregion
        #region InsertRewards!
        Storage_InsertItem(context, totalRewardArr);
        #endregion

        return(GetDefaultJObject(context));
    }
Exemplo n.º 3
0
    public static JObject enc_sess_craft_insertrecipe(FIFakeContext context)
    {
        CheckParameterExists(context, "tableUID", "recipeID");
        var tableUID = context.body["tableUID"].Value <int>();
        var recipeID = context.body["recipeID"].Value <int>();

        var runtimeTable = context.dbContext.GetByID <DBCraftingTable>(tableUID);
        var staticTable  = context.staticData.GetByID <GDCraftingTable>(runtimeTable.craftingTableID);

        var staticRecipe = context.staticData.GetByID <GDCraftRecipeData>(recipeID);
        var reqItemArr   = staticRecipe.reqItemArr.Select(x => {
            return(Tuple.Create <int, int>(x.item.id, x.cnt));
        }).ToArray();
        var unlockedRecipe = context.dbContext.GetList <DBCraftingRecipeUnlock>()
                             .Where(x => x.recipeID == staticRecipe.id).FirstOrDefault();
        var currentRecipeList = context.dbContext.GetList <DBCraftingItem>()
                                .Where(x => x.tableUID == tableUID)
                                .OrderBy(x => x.insertedTime)
                                .ToList();

        var availableQueue    = staticTable.minSlot + runtimeTable.upgradeLv;
        var completeQueueSize = context.easy.GlobalInfo.totalCraftedCompleteCnt;

        var curServerTime       = CurrentTime;
        var estimateStartedTime = runtimeTable.recipeStartedTime;

        //Check
        #region Check I learned recipe!
        if (unlockedRecipe == null)
        {
            throw new FIException(FIErr.Crafting_CannotInsertRecipeNotUnlockedRecipe);
        }
        #endregion
        #region Check has enough resource..
        if (Storage_CheckCanDisposeItems(context, reqItemArr) == false)
        {
            throw new FIException(FIErr.Crafting_CannotInsertRecipeNotEnoughIngredient);
        }
        #endregion
        #region Check i can insert more
        var  passedTime          = curServerTime - estimateStartedTime;
        bool isUnhold            = false;
        var  currentMakingItem   = FIShareCraftFunc.GetCurrentCookingRecipe(completeQueueSize, passedTime, currentRecipeList, out isUnhold);
        var  currentCompleteList = FIShareCraftFunc.GetMadeDishList(completeQueueSize, passedTime, currentRecipeList);
        var  realLeftQueue       = availableQueue - (currentRecipeList.Count - currentCompleteList.Count);
        if (realLeftQueue <= 0)
        {
            throw new FIException(FIErr.Crafting_CannotInsertRecipeNoRoomForQueue);
        }
        #endregion



        //Action
        #region Reset time
        if (currentRecipeList.Count <= 0)
        {
            estimateStartedTime            = curServerTime;
            runtimeTable.recipeStartedTime = estimateStartedTime;
            InsertUpdated(context, runtimeTable);
        }
        else if (isUnhold == false & currentMakingItem == null)
        {
            estimateStartedTime            = curServerTime - FIShareCraftFunc.CalculateFinishedProductTime(currentCompleteList);
            runtimeTable.recipeStartedTime = estimateStartedTime;
            InsertUpdated(context, runtimeTable);
        }

        #endregion
        #region Dispose ReqItemArr
        Storage_DisposeItem(context, reqItemArr);
        #endregion
        #region Insert Recipe
        var created = context.dbContext.Create <DBCraftingItem>();
        created.tableUID     = tableUID;
        created.insertedTime = CurrentTime;
        created.recipeID     = recipeID;
        created.reqTime      = staticRecipe.reqTime;
        InsertUpdated(context, created);
        #endregion
        return(GetDefaultJObject(context));
    }