/// <summary>
        /// Function that logs an action taken in the level.
        /// </summary>
        /// <returns>Nothing</returns>
        /// <param name="actionId">A number that you assign that maps
        /// to a particular action that you are interested in recording.
        /// Each action type should have a unique number that is kept
        /// consistent across sessions.</param>
        /// <param name="details">Any details associated with the action
        /// (e.g. location, target, success, etc.)</param>
        /// <remarks>Because it is expected that the game will log player
        /// actions frequently, level actions are buffered and are
        /// flushed in batches to the server as the implementation
        /// sees fit. Level actions will also be flushed when
        /// <see cref="LogLevelEnd(string)"/> or <see cref="FlushBufferedLevelActions"/>
        /// are called. </remarks>
        public void LogLevelAction(int actionId, string details)
        {
            // Per action, figure out the time since the start of the level
            DateTime timestampOfAction = DateTime.Now;
            TimeSpan relativeTime      = timestampOfAction - this.timestampOfPrevLevelStart;
            var      individualAction  = new LevelAction {
                detail        = details,
                client_ts     = timestampOfAction.TotalMilliseconds(),
                ts            = relativeTime.TotalMilliseconds,
                te            = relativeTime.TotalMilliseconds,
                session_seqid = ++this.currentActionSeqInSession,
                qaction_seqid = ++this.currentActionSeqInLevel,
                aid           = actionId
            };

            this.levelActionBuffer.Add(individualAction);

            // Flush buffer if it exceeds a certain length or some amount of time has elapsed since
            // the last time we flushed the buffer.
            double timeSinceLastAction = (timestampOfAction - this.timestampOfPrevAction).TotalMilliseconds;

            if (levelActionBuffer.Count >= 5 || timeSinceLastAction > 2000)
            {
                this.FlushBufferedLevelActions();
            }
            this.timestampOfPrevAction = DateTime.Now;
        }
Esempio n. 2
0
    public void PerformAction(ActionType actionType)
    {
        if (actionsList.Count > 0)
        {
            bool found = false;
            for (int i = 0; i < actionsList.Count && !found; i++)
            {
                if (actionType == actionsList[i].actionType)
                {
                    found = true;
                    LevelAction action = actionsList[i];
                    actionsList.RemoveAt(i);

                    switch (actionType)
                    {
                    case ActionType.PlantTree:
                        treesPlanted++;
                        break;

                    case ActionType.BuildBridge:
                        bridgesBuilt++;
                        break;

                    case ActionType.WaterTree:
                        treesWatered++;
                        break;

                    case ActionType.SpawnCow:
                        cowsSpawned++;
                        break;

                    case ActionType.CowDied:
                        cowsSpawned--;
                        break;

                    case ActionType.TreeDied:
                        treesPlanted--;
                        break;

                    case ActionType.CraftTree:
                        treesCrafted++;
                        break;
                    }

                    action.functionsWhenFinished.Invoke();
                }
            }
        }
        CheckIfLevelCompleted();
    }
Esempio n. 3
0
        internal void NotifyAction(LevelAction a, bool undo)
        {
            if (a.AffectedLevel != loadedData.Level)
            {
                return;
            }

            using (BeginUpdate()) {
                Actions.ModifyObject modAction = a as Actions.ModifyObject;
                if (modAction != null && modAction.AffectedLevel == data.Level && modAction.GetItem() is StructInstance)
                {
                    if (((StructInstance)modAction.GetItem()).ObjectType == StructIndex && modAction.Change == Editroid.Actions.ObjectModification.Palette)
                    {
                        loadedData.PaletteIndex = LoadedData.Invalid;
                    }
                }

                Actions.SetPaletteColor palAction = a as Actions.SetPaletteColor;
                if (palAction != null)
                {
                    if (palAction.AffectedLevel == data.Level && (palAction.PaletteIndex == data.PaletteIndex || palAction.EntryIndex == 0))
                    {
                        loadedData.PaletteIndex = LoadedData.Invalid;
                    }
                }
            }


            Editroid.Actions.ModifyCombo comboAction = a as Editroid.Actions.ModifyCombo;
            if (comboAction != null)
            {
                if (comboAction.Changes.Count == 1)
                {
                    comboEditor.DrawCombo(comboAction.Changes[0].index, true);
                }
                else
                {
                    comboEditor.Draw();
                }
            }

            loadedData.StructIndex = LoadedData.Invalid;
            PerformUpdates();
        }
Esempio n. 4
0
    public void ProcessAction(LevelAction levelAction)
    {
        bool canIncrement = true;

        switch (levelAction.actionType)
        {
        case ActionType.SpawnBigScrap:
            int spawnAmount = int.Parse(levelAction.argument);
            SpawnBigScrap(spawnAmount);
            break;

        case ActionType.AddGizmoidButton:
            canIncrement = false;
            var gizmoidId = int.Parse(levelAction.argument);
            AddGizmoidButtons(gizmoidId);
            break;

        case ActionType.SpawnSmallScrap:
            collectibleSpawner.SpawnScrap(int.Parse(levelAction.argument), false);
            break;

        case ActionType.AutoSpawnAll:
            try
            {
                var can = Convert.ToBoolean(levelAction.argument);
                collectibleSpawner.SpawningScrap        = can;
                collectibleSpawner.SpawningCollectibles = can;
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            break;

        case ActionType.AutoSpawnScrap:
            try
            {
                collectibleSpawner.SpawningScrap = Convert.ToBoolean(levelAction.argument);
            }
            catch (Exception)
            {
                throw;
            }
            break;

        case ActionType.AutoSpawnCollectible:
            try
            {
                collectibleSpawner.SpawningCollectibles = Convert.ToBoolean(levelAction.argument);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            break;

        case ActionType.AllowDropCollectible:
            try
            {
                collectibleSpawner.allowRareDrop = Convert.ToBoolean(levelAction.argument);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            break;

        case ActionType.AllowDropScrap:
            try
            {
                collectibleSpawner.allowScrapDrop = Convert.ToBoolean(levelAction.argument);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            break;

        case ActionType.RotateShip:
            float target = 0;
            float.TryParse(levelAction.argument, out target);
            shipController.ForceRotate(target, 0.5f, true);
            break;

        case ActionType.AddBlade:
            canIncrement = false;
            int bladeAmount = int.Parse(levelAction.argument);
            bladeController.onBladesPlaced.AddListener(OnBladePlaced);
            bladeController.PlaceBlades(bladeAmount);
            break;

        case ActionType.InsertGizmoid:
            var   argumentStrings = levelAction.argument.Split(new string[] { ";" }, System.StringSplitOptions.RemoveEmptyEntries);
            int[] argumentInts    = new int[argumentStrings.Length];
            for (int i = 0; i < argumentInts.Length; i++)
            {
                argumentInts[i] = int.Parse(argumentStrings[i]);
            }
            InjectGizmoid(argumentInts[0], argumentInts[2]);
            break;

        case ActionType.Unlock:
            playerProgress.AddFeatures(levelAction.argument);
            break;

        case ActionType.GizmoidButtonInteractive:
            bool active = true;
            try
            {
                active = Convert.ToBoolean(levelAction.argument);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
            gameplayInterface.entityButtonContainer.SetInteractivity(active);
            break;

        case ActionType.None:
        default:
            break;
        }
        if (canIncrement)
        {
            IncrementAct();
        }
    }
Esempio n. 5
0
 public void addToActionList(LevelAction l)
 {
     actionsList.Add(l);
 }