Ejemplo n.º 1
0
 ///<summary>
 ///constructor for composite goal GetItem
 ///</summary>
 ///<param name="bot">bot entity that owns this goal</param>
 ///<param name="itemToGet">item to get</param>
 public GetItem(BotEntity bot, ItemTypes itemToGet)
     : base(bot, ItemTypeToGoalType(itemToGet))
 {
     _itemToGet = itemToGet;
     _giverTrigger = null;
     _logItemToGetText =
         String.Format(" Item: [{0,-12}]",
                       EnumUtil.GetDescription(_itemToGet));
 }
Ejemplo n.º 2
0
        public static void LoadGameItem(byte[] itemData, int storageIndex, out int itemType, out object item)
        {
            item = null;
            var itemName = $"GameItem{storageIndex}";
            var reader   = new BinaryReader(new MemoryStream(itemData));

            itemType = reader.ReadInt32();
            switch (itemType)
            {
            case ItemType.Bumper: item = new Bumper.Bumper(reader, itemName); break;

            case ItemType.Flasher: item = new Flasher.Flasher(reader, itemName); break;

            case ItemType.Flipper: item = new Flipper.Flipper(reader, itemName); break;

            case ItemType.Gate: item = new Gate.Gate(reader, itemName); break;

            case ItemType.HitTarget: item = new HitTarget.HitTarget(reader, itemName); break;

            case ItemType.Kicker: item = new Kicker.Kicker(reader, itemName); break;

            case ItemType.Light: item = new Light.Light(reader, itemName); break;

            case ItemType.Primitive: item = new Primitive.Primitive(reader, itemName); break;

            case ItemType.Ramp: item = new Ramp.Ramp(reader, itemName); break;

            case ItemType.Rubber: item = new Rubber.Rubber(reader, itemName); break;

            case ItemType.Spinner: item = new Spinner.Spinner(reader, itemName); break;

            case ItemType.Surface: item = new Surface.Surface(reader, itemName); break;

            case ItemType.Trigger: item = new Trigger.Trigger(reader, itemName); break;

            default: itemType = -1; break;
            }
        }
Ejemplo n.º 3
0
        ///<summary>
        ///logic to run when the goal is activated.
        ///</summary>
        public override void Activate()
        {
            LogUtil.WriteLineIfLogGetItem(
                LogPrefixText + LogActivateText + LogStatusText + LogItemToGetText);

            Status = StatusTypes.Active;

            _giverTrigger = null;

            LogUtil.WriteLineIfLogGetItem(
                LogPrefixText + LogActivateText + LogStatusText + LogItemToGetText +
                " RequestPathToItem");

            //request a path to the item
            Bot.PathPlanner.RequestPathToItem(_itemToGet, Bot);

            LogUtil.WriteLineIfLogGetItem(
                LogPrefixText + LogActivateText + LogStatusText + LogItemToGetText +
                LogAddSubgoalText + "Wander");

            //the bot may have to wait a few update cycles before a path is
            //calculated so for appearances sake it just wanders
            AddSubgoal(new Wander(Bot));
        }
Ejemplo n.º 4
0
        private static void LoadGameItems(Table table, CFStorage storage)
        {
            for (var i = 0; i < table.Data.NumGameItems; i++)
            {
                var itemName = $"GameItem{i}";
                storage.TryGetStream(itemName, out var itemStream);
                if (itemStream == null)
                {
                    Logger.Warn("Could not find stream {0}, skipping.", itemName);
                    continue;
                }
                var itemData = itemStream.GetData();
                if (itemData.Length < 4)
                {
                    Logger.Warn("Skipping {itemName} because it has size of {itemDataLength}.", itemName, itemData.Length);
                    continue;
                }

                var reader   = new BinaryReader(new MemoryStream(itemData));
                var itemType = reader.ReadInt32();
                switch (itemType)
                {
                case ItemType.Bumper: {
                    var item = new VisualPinball.Engine.VPT.Bumper.Bumper(reader, itemName);
                    table.Bumpers[item.Name] = item;
                    break;
                }

                case ItemType.Decal: {
                    table.Decals.Add(new VisualPinball.Engine.VPT.Decal.Decal(reader, itemName));
                    break;
                }

                case ItemType.DispReel: {
                    var item = new VisualPinball.Engine.VPT.DispReel.DispReel(reader, itemName);
                    table.DispReels[item.Name] = item;
                    break;
                }

                case ItemType.Flasher: {
                    var item = new VisualPinball.Engine.VPT.Flasher.Flasher(reader, itemName);
                    table.Flashers[item.Name] = item;
                    break;
                }

                case ItemType.Flipper: {
                    var item = new VisualPinball.Engine.VPT.Flipper.Flipper(reader, itemName);
                    table.Flippers[item.Name] = item;
                    break;
                }

                case ItemType.Gate: {
                    var item = new VisualPinball.Engine.VPT.Gate.Gate(reader, itemName);
                    table.Gates[item.Name] = item;
                    break;
                }

                case ItemType.HitTarget: {
                    var item = new VisualPinball.Engine.VPT.HitTarget.HitTarget(reader, itemName);
                    table.HitTargets[item.Name] = item;
                    break;
                }

                case ItemType.Kicker: {
                    var item = new VisualPinball.Engine.VPT.Kicker.Kicker(reader, itemName);
                    table.Kickers[item.Name] = item;
                    break;
                }

                case ItemType.Light: {
                    var item = new VisualPinball.Engine.VPT.Light.Light(reader, itemName);
                    table.Lights[item.Name] = item;
                    break;
                }

                case ItemType.LightSeq: {
                    var item = new VisualPinball.Engine.VPT.LightSeq.LightSeq(reader, itemName);
                    table.LightSeqs[item.Name] = item;
                    break;
                }

                case ItemType.Plunger: {
                    var item = new VisualPinball.Engine.VPT.Plunger.Plunger(reader, itemName);
                    table.Plungers[item.Name] = item;
                    break;
                }

                case ItemType.Primitive: {
                    var item = new Primitive.Primitive(reader, itemName);
                    table.Primitives[item.Name] = item;
                    break;
                }

                case ItemType.Ramp: {
                    var item = new Ramp.Ramp(reader, itemName);
                    table.Ramps[item.Name] = item;
                    break;
                }

                case ItemType.Rubber: {
                    var item = new Rubber.Rubber(reader, itemName);
                    table.Rubbers[item.Name] = item;
                    break;
                }

                case ItemType.Spinner: {
                    var item = new Spinner.Spinner(reader, itemName);
                    table.Spinners[item.Name] = item;
                    break;
                }

                case ItemType.Surface: {
                    var item = new Surface.Surface(reader, itemName);
                    table.Surfaces[item.Name] = item;
                    break;
                }

                case ItemType.Textbox: {
                    var item = new TextBox.TextBox(reader, itemName);
                    table.TextBoxes[item.Name] = item;
                    break;
                }

                case ItemType.Timer: {
                    var item = new Timer.Timer(reader, itemName);
                    table.Timers[item.Name] = item;
                    break;
                }

                case ItemType.Trigger: {
                    var item = new Trigger.Trigger(reader, itemName);
                    table.Triggers[item.Name] = item;
                    break;
                }
                }
            }
        }
Ejemplo n.º 5
0
        public static void LoadGameItem(byte[] itemData, int storageIndex, out ItemType itemType, out object item)
        {
            item = null;
            var itemName = $"GameItem{storageIndex}";
            var reader   = new BinaryReader(new MemoryStream(itemData));

            // parse to enum
            var iItemType = reader.ReadInt32();

            if (!Enum.IsDefined(typeof(ItemType), iItemType))
            {
                Logger.Info("Invalid item type " + iItemType);
                itemType = ItemType.Invalid;
                return;
            }

            itemType = (ItemType)iItemType;
            switch (itemType)
            {
            case ItemType.Bumper: item = new Bumper.Bumper(reader, itemName); break;

            case ItemType.Decal: item = new Decal.Decal(reader, itemName); break;

            case ItemType.DispReel: item = new DispReel.DispReel(reader, itemName); break;

            case ItemType.Flasher: item = new Flasher.Flasher(reader, itemName); break;

            case ItemType.Flipper: item = new Flipper.Flipper(reader, itemName); break;

            case ItemType.Gate: item = new Gate.Gate(reader, itemName); break;

            case ItemType.HitTarget: item = new HitTarget.HitTarget(reader, itemName); break;

            case ItemType.Kicker: item = new Kicker.Kicker(reader, itemName); break;

            case ItemType.Light: item = new Light.Light(reader, itemName); break;

            case ItemType.LightSeq: item = new LightSeq.LightSeq(reader, itemName); break;

            case ItemType.Plunger: item = new Plunger.Plunger(reader, itemName); break;

            case ItemType.Primitive: item = new Primitive.Primitive(reader, itemName); break;

            case ItemType.Ramp: item = new Ramp.Ramp(reader, itemName); break;

            case ItemType.Rubber: item = new Rubber.Rubber(reader, itemName); break;

            case ItemType.Spinner: item = new Spinner.Spinner(reader, itemName); break;

            case ItemType.Surface: item = new Surface.Surface(reader, itemName); break;

            case ItemType.TextBox: item = new TextBox.TextBox(reader, itemName); break;

            case ItemType.Timer: item = new Timer.Timer(reader, itemName); break;

            case ItemType.Trigger: item = new Trigger.Trigger(reader, itemName); break;

            case ItemType.Trough: item = new Trough.Trough(reader, itemName); break;

            default:
                Logger.Info("Unhandled item type " + itemType);
                itemType = ItemType.Invalid; break;
            }
        }
Ejemplo n.º 6
0
        ///<summary>
        ///handle messages
        ///</summary>
        ///<param name="msg"></param>
        ///<returns></returns>
        public override bool HandleMessage(Telegram msg)
        {
            //first, pass the message down the goal hierarchy
            bool isHandled = ForwardMessageToFrontMostSubgoal(msg);

            if (isHandled)
            {
                LogUtil.WriteLineIfLogGetItem(
                    LogPrefixText + LogHandleMessageText + LogStatusText +
                    LogItemToGetText + " Message handled by subgoal");
            }

            //if the msg was not handled, test to see if this goal can handle it
            if (!isHandled)
            {
                switch (msg.Msg)
                {
                    case MessageTypes.PathReady:
                        LogUtil.WriteLineIfLogGetItem(
                            LogPrefixText + LogHandleMessageText + LogStatusText +
                            LogItemToGetText + " Msg: path ready");
                        //clear any existing goals
                        RemoveAllSubgoals();
                        LogUtil.WriteLineIfLogGetItem(
                            LogPrefixText + LogHandleMessageText + LogStatusText +
                            LogAddSubgoalText + "FollowPath: " + PathToString());
                        AddSubgoal(
                            new FollowPath(Bot, Bot.PathPlanner.GetPath()));
                        //get the reference to the item
                        _giverTrigger = msg.ExtraInfo as Trigger.Trigger;
                        return true; //msg handled

                    case MessageTypes.NoPathAvailable:
                        Status = StatusTypes.Failed;
                        LogUtil.WriteLineIfLogGetItem(
                            LogPrefixText + LogHandleMessageText + LogStatusText +
                            LogItemToGetText + " Msg: no path available");
                        return true; //msg handled

                    default:
                        return false;
                }
            }

            //handled by subgoals
            return true;
        }
Ejemplo n.º 7
0
        private static void LoadGameItems(FileTableContainer tableContainer, CFStorage storage, int count, string storagePrefix)
        {
            for (var i = 0; i < count; i++)
            {
                var itemName = $"{storagePrefix}{i}";
                storage.TryGetStream(itemName, out var itemStream);
                if (itemStream == null)
                {
                    Logger.Warn("Could not find stream {0}, skipping.", itemName);
                    continue;
                }
                var itemData = itemStream.GetData();
                if (itemData.Length < 4)
                {
                    Logger.Warn("Skipping {itemName} because it has size of {itemDataLength}.", itemName, itemData.Length);
                    continue;
                }

                var reader = new BinaryReader(new MemoryStream(itemData));

                // parse to enum
                var iItemType = reader.ReadInt32();
                if (!Enum.IsDefined(typeof(ItemType), iItemType))
                {
                    Logger.Info("Invalid item type " + iItemType);
                    return;
                }

                var itemType = (ItemType)iItemType;
                switch (itemType)
                {
                case ItemType.Bumper: {
                    var item = new VisualPinball.Engine.VPT.Bumper.Bumper(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Decal: {
                    tableContainer.Add(new VisualPinball.Engine.VPT.Decal.Decal(reader, itemName));
                    break;
                }

                case ItemType.DispReel: {
                    var item = new VisualPinball.Engine.VPT.DispReel.DispReel(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Flasher: {
                    var item = new VisualPinball.Engine.VPT.Flasher.Flasher(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Flipper: {
                    var item = new VisualPinball.Engine.VPT.Flipper.Flipper(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Gate: {
                    var item = new VisualPinball.Engine.VPT.Gate.Gate(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.HitTarget: {
                    var item = new VisualPinball.Engine.VPT.HitTarget.HitTarget(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Kicker: {
                    var item = new VisualPinball.Engine.VPT.Kicker.Kicker(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Light: {
                    var item = new VisualPinball.Engine.VPT.Light.Light(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.LightSeq: {
                    var item = new VisualPinball.Engine.VPT.LightSeq.LightSeq(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Plunger: {
                    var item = new VisualPinball.Engine.VPT.Plunger.Plunger(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Primitive: {
                    var item = new Primitive.Primitive(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Ramp: {
                    var item = new Ramp.Ramp(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Rubber: {
                    var item = new Rubber.Rubber(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Spinner: {
                    var item = new Spinner.Spinner(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Surface: {
                    var item = new Surface.Surface(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.TextBox: {
                    var item = new TextBox.TextBox(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Timer: {
                    var item = new Timer.Timer(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Trigger: {
                    var item = new Trigger.Trigger(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.Trough: {
                    var item = new Trough.Trough(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }

                case ItemType.MetalWireGuide:
                {
                    var item = new MetalWireGuide.MetalWireGuide(reader, itemName);
                    tableContainer.Add(item);
                    break;
                }
                }
            }
        }
Ejemplo n.º 8
0
 public void addTrigger(Trigger.Trigger trigger)
 {
     triggers.Add(trigger);
 }