示例#1
0
 public virtual void Tick(RealmTime time)
 {
     if (this is Projectile)
     {
         return;
     }
     if (interactive && Owner != null)
     {
         if (BehaviorBase.HasPlayerNearby(this) &&
             !HasConditionEffect(ConditionEffects.Stasis))
         {
             MovementBehavior.Tick(this, time);
             AttackBehavior.Tick(this, time);
             ReproduceBehavior.Tick(this, time);
         }
         foreach (var i in CondBehaviors)
         {
             if ((i.Condition & BehaviorCondition.Other) != 0 &&
                 i.ConditionMeet(this))
             {
                 i.Behave(BehaviorCondition.Other, this, time, null);
             }
         }
         posHistory[posIdx++] = new Position()
         {
             X = X, Y = Y
         };
         ProcessConditionEffects(time);
     }
 }
示例#2
0
    protected virtual void OnAwake()
    {
        mr = GetComponent <MeshRenderer>();

        if (mr != null)
        {
            switch (spriteType)
            {
            case SpriteType.Omni:
                mr.material = MaterialManager.Instance.omniBillboardMaterial;
                break;

            case SpriteType.Axis:
                mr.material = MaterialManager.Instance.axisBillboardMaterial;
                break;

            case SpriteType.TransparentOmni:
                mr.material = MaterialManager.Instance.transparentOmniBillboardMaterial;
                break;

            case SpriteType.TransparentAxis:
                mr.material = MaterialManager.Instance.transparentAxisBillboardMaterial;
                break;
            }
        }

        if (BehaviorType != BehaviorBase.Behaviors.None)
        {
            CurrentBehavior       = BehaviorBase.Instantiate(BehaviorType);
            CurrentBehavior.owner = this;
            CurrentBehavior.Init();
        }
    }
示例#3
0
        public override void Tick(RealmTime time)
        {
            if (t / 500 == p)
            {
                Owner.BroadcastPacket(new ShowEffectPacket
                {
                    EffectType = EffectType.Trap,
                    Color      = new ARGB(0xff9000ff),
                    TargetId   = Id,
                    PosA       = new Position {
                        X = radius
                    }
                }, null);
                p++;
                if (p == LIFETIME * 2)
                {
                    Explode(time);
                    return;
                }
            }
            t += time.thisTickTimes;

            var monsterNearby = false;

            BehaviorBase.AOE(Owner, this, radius / 2, false, enemy => monsterNearby = true);
            if (monsterNearby)
            {
                Explode(time);
            }

            base.Tick(time);
        }
示例#4
0
 private static void DeactiveAllBehaviorsOfSameKind(BehaviorBase[] listOfSameType)
 {
     foreach (var item in listOfSameType)
     {
         item.Active = false;
     }
 }
        public static AIActor GetAttackBehaviourOwner(this BehaviorBase behav)
        {
            AIActor actor = null;

            actor = OMITBReflectionHelpers.ReflectGetField <AIActor>(typeof(BehaviorBase), "m_aiActor", behav);
            return(actor);
        }
示例#6
0
    private static void ToggleAvailibility(BehaviorBase behavior, bool newValue)
    {
        var behaviors = FindObjectOfType<Runner>().GetComponentsInChildren<TileSelection>();

        foreach (var item in behaviors.Where(x => x.Selected))
        {
            item.GetComponent<Behaviors>().GetBehavior(behavior.Name).Available = newValue;
        }
    }
示例#7
0
 private void SetLookAndFeel(BehaviorBase[] behaviors, GameObject[] buttons)
 {
     for (int i = 0; i < behaviors.Length; i++)
     {
         var behavior = behaviors[i];
         var button = buttons[i];
         button.GetComponent<Layout>()
             .SetLayoutBasedOnBehavior(behavior);
     }
 }
示例#8
0
文件: Oryx.cs 项目: ethus3h/LR-v1
        private int Spawn(ObjectDesc desc, WmapTerrain terrain, int w, int h)
        {
            Entity entity;
            var    ret = 0;
            var    pt  = new IntPoint();

            if (desc.Spawn != null)
            {
                var num = (int)GetNormal(rand, desc.Spawn.Mean, desc.Spawn.StdDev);
                if (num > desc.Spawn.Max)
                {
                    num = desc.Spawn.Max;
                }
                else if (num < desc.Spawn.Min)
                {
                    num = desc.Spawn.Min;
                }

                do
                {
                    pt.X = rand.Next(0, w);
                    pt.Y = rand.Next(0, h);
                } while (world.Map[pt.X, pt.Y].Terrain != terrain ||
                         world.Obstacles[pt.X, pt.Y] != 0 ||
                         BehaviorBase.HasPlayerNearby(world, pt.X, pt.Y));

                for (var k = 0; k < num; k++)
                {
                    entity = Entity.Resolve(desc.ObjectType);
                    entity.Move(
                        pt.X + (float)(rand.NextDouble() * 2 - 1) * 5,
                        pt.Y + (float)(rand.NextDouble() * 2 - 1) * 5);
                    (entity as Enemy).Terrain = terrain;
                    world.EnterWorld(entity);
                    ret++;
                }
            }
            else
            {
                do
                {
                    pt.X = rand.Next(0, w);
                    pt.Y = rand.Next(0, h);
                } while (world.Map[pt.X, pt.Y].Terrain != terrain ||
                         world.Obstacles[pt.X, pt.Y] != 0 ||
                         BehaviorBase.HasPlayerNearby(world, pt.X, pt.Y));

                entity = Entity.Resolve(desc.ObjectType);
                entity.Move(pt.X, pt.Y);
                (entity as Enemy).Terrain = terrain;
                world.EnterWorld(entity);
                ret++;
            }
            return(ret);
        }
示例#9
0
文件: EnemyBase.cs 项目: moedevs/PECO
 protected virtual void Awake()
 {
     try {
         viewRangeLight = transform.GetChild(0).gameObject;
     } catch {
         Debug.LogError("Failed to get FOV Light child object of " + gameObject);
     }
     behavior = GetComponent <BehaviorBase>();
     anim     = GetComponent <Animator>();
     health   = maxHealth;
 }
示例#10
0
    public void SetOptions(BehaviorBase[] behaviors, BehaviorTypes type)
    {
        if (type == BehaviorTypes.Actions)
        {
            SetLookAndFeel(behaviors, ActionButtons);
        }

        if (type == BehaviorTypes.Triggers)
        {
            SetLookAndFeel(behaviors, TriggerButtons);
        }
    }
示例#11
0
        public void SetParameter(string name, BehaviorBase value)
        {
            var list = Parameters.ToList();

            list.Add(new ParameterXml
            {
                Name     = name,
                Next     = XmlExporter.ExportBehavior(value),
                Behavior = true
            });

            Parameters = list.ToArray();
        }
示例#12
0
        /// <summary>
        /// called often, must return promptly. It is a thread safe function.
        /// </summary>
        public override void Process()
        {
            StartedLoop();

            // every cycle we create new behaviorData, populating it with existing data objects:
            IBehaviorData behaviorData = new BehaviorData()
            {
                sensorsData = this.currentSensorsData,
                robotState  = this.robotState,
                robotPose   = this.robotPose
            };

            // use sensor data to update robotPose:
            robotSlam.EvaluatePoseAndState(behaviorData, driveController);

            // populate all behaviors with current behaviorData:
            foreach (ISubsumptionTask task in subsumptionTaskDispatcher.Tasks)
            {
                BehaviorBase behavior = task as BehaviorBase;

                if (behavior != null)
                {
                    behavior.behaviorData = behaviorData;
                }
            }

            subsumptionTaskDispatcher.Process();     // calls behaviors, which take sensor outputs, and may compute drive inputs

            // look at ActiveTasksCount - it is an indicator of behaviors completed or removed. Zero count means we may need new behaviors combo.
            MonitorDispatcherActivity();

            // when active behavior is waiting (yielding), no action items are computed.
            // otherwise driveInputs will be non-null:
            if (behaviorData.driveInputs != null)
            {
                //Debug.WriteLine("ShortyTheRobot: Process()   - have drive inputs V=" + behaviorData.driveInputs.velocity + "   Omega=" + behaviorData.driveInputs.omega);

                driveController.driveInputs = behaviorData.driveInputs;

                driveController.Drive();    // apply driveInputs to motors

                robotState.velocity = behaviorData.driveInputs.velocity;
                robotState.omega    = behaviorData.driveInputs.omega;
            }

            this.BehaviorData = behaviorData;   // for tracing

            sensorsController.Process();        // let sensorsController do maintenance

            EndingLoop();
        }
    public void ClearPreview()
    {
        if (_preview != null)
        {
            _preview.ClearUI();
        }
        if (_covering != null)
        {
            _covering.UpdateUI();
        }

        _preview = null;
        _covering = null;
    }
示例#14
0
        protected void RegisterBehavior(BehaviorBase behavior)
        {
            if (behavior != null)
            {
                if (_behaviors == null)
                {
                    _behaviors = new List <BehaviorBase>();
                }

                _behaviors.Add(behavior);

                behavior.Register(this);
            }
        }
示例#15
0
 public void SetLayoutBasedOnBehavior(BehaviorBase behavior)
 {
     behavior.ClearUI(gameObject);
     behavior.UpdateUI(gameObject, false);
     gameObject.SetActive(true);
     gameObject.name = behavior.Name;
     if (Globals.InputMode == InputMode.Buttons)
     {
         GetComponent<ButtonEnabled>().ContentEnabled = false;
     }
     else
     {
         GetComponent<ButtonEnabled>().ContentEnabled = true;
     }
 }
示例#16
0
文件: Oryx.cs 项目: ethus3h/LR-v1
        private void SpawnEvent(ISetPiece setpiece)
        {
            var pt = new IntPoint();

            do
            {
                pt.X = rand.Next(0, world.Map.Width);
                pt.Y = rand.Next(0, world.Map.Height);
            } while ((world.Map[pt.X, pt.Y].Terrain <WmapTerrain.Mountains ||
                                                     world.Map[pt.X, pt.Y].Terrain> WmapTerrain.MidForest) ||
                     world.Obstacles[pt.X, pt.Y] != 0 ||
                     BehaviorBase.HasPlayerNearby(world, pt.X, pt.Y));

            pt.X -= (setpiece.Size - 1) / 2;
            pt.Y -= (setpiece.Size - 1) / 2;
            setpiece.RenderSetPiece(world, pt);
        }
示例#17
0
 private void Explode(RealmTime time)
 {
     Owner.BroadcastPacket(new ShowEffectPacket
     {
         EffectType = EffectType.AreaBlast,
         Color      = new ARGB(0xff9000ff),
         TargetId   = Id,
         PosA       = new Position {
             X = radius
         }
     }, null);
     BehaviorBase.AOE(Owner, this, radius, false, enemy =>
     {
         (enemy as Enemy).Damage(player, time, dmg, false, new ConditionEffect
         {
             Effect     = effect,
             DurationMS = duration
         });
     });
     Owner.LeaveWorld(this);
 }
示例#18
0
        private BehaviorsCoordinatorData coordinatorData = BehaviorBase.getCoordinatorData();  // get the singleton

        /// <summary>
        /// behaviors in dispatcher may all exit, which will require producing a new behaviors combo.
        /// </summary>
        private void MonitorDispatcherActivity()
        {
            // ActiveTasksCount is indicator of behaviors completed or removed. Zero count means we may need new behaviors combo.
            int dispatcherActiveTasksCount = subsumptionTaskDispatcher.ActiveTasksCount;

            if (dispatcherActiveTasksCount != lastActiveTasksCount)
            {
                Debug.WriteLine("Warning: ShortyTheRobot: Process: active tasks count: " + dispatcherActiveTasksCount);

                if (dispatcherActiveTasksCount == 0)
                {
                    this.SafePose(); // ensure the robot is stopped when all behaviors have exited
                    speaker.Speak("active tasks count zero");
                }
                else if (lastActiveTasksCount <= 0)
                {
                    speaker.Speak(string.Format("{0} tasks", dispatcherActiveTasksCount));
                }

                lastActiveTasksCount = dispatcherActiveTasksCount;
            }

            // clear the grab, if any:
            string gbn = coordinatorData.GrabbingBehaviorName;

            if (!string.IsNullOrWhiteSpace(gbn))
            {
                ISubsumptionTask grabber = (from b in subsumptionTaskDispatcher.Tasks where b.name == gbn select b).FirstOrDefault();

                if (grabber != null)
                {
                    BehaviorBase bBase = (BehaviorBase)grabber;
                    if (!bBase.FiredOn)
                    {
                        // Grabbing behavior is not firing any more, can clear the grab:
                        coordinatorData.ClearGrabbingBehavior();
                    }
                }
            }
        }
示例#19
0
 public override void Tick(RealmTime time)
 {
     if (t / 500 == p2)
     {
         Owner.BroadcastPacket(new ShowEffectPacket
         {
             EffectType = EffectType.Trap,
             Color      = new ARGB(0xffd700),
             TargetId   = Id,
             PosA       = new Position {
                 X = radius
             }
         }, null);
         p2++;
         //Stuff
     }
     if (t / 2000 == p)
     {
         var pkts = new List <Packet>();
         BehaviorBase.AOE(Owner, this, radius, true,
                          player => { Player.ActivateHealHp(player as Player, amount, pkts); });
         pkts.Add(new ShowEffectPacket
         {
             EffectType = EffectType.AreaBlast,
             TargetId   = Id,
             Color      = new ARGB(0xffd700),
             PosA       = new Position {
                 X = radius
             }
         });
         Owner.BroadcastPackets(pkts, null);
         p++;
     }
     t += time.thisTickTimes;
     base.Tick(time);
 }
示例#20
0
 public override void Tick(RealmTime time)
 {
     if (HP > duration / 2)
     {
         BehaviorBase.ValidateAndMove(this,
                                      X + direction.X * speed * time.thisTickTimes / 1000,
                                      Y + direction.Y * speed * time.thisTickTimes / 1000
                                      );
     }
     if (HP < 250 && !exploded)
     {
         exploded = true;
         Owner.BroadcastPacket(new ShowEffectPacket
         {
             EffectType = EffectType.AreaBlast,
             Color      = new ARGB(0xffff0000),
             TargetId   = Id,
             PosA       = new Position {
                 X = 1
             }
         }, null);
     }
     base.Tick(time);
 }
示例#21
0
 public override void Tick(RealmTime time)
 {
     if (t / 1500 == p)
     {
         p = 100;
         var   pkts    = new List <Packet>();
         var   enemies = new List <Enemy>();
         short obj;
         var   pt = monster;
         db.data.XmlDatas.IdToType.TryGetValue(pt, out obj);
         BehaviorBase.AOE(Owner, this, radius, false, enemy =>
         {
             enemies.Add(enemy as Enemy);
         });
         Owner.BroadcastPacket(new ShowEffectPacket
         {
             EffectType = EffectType.AreaBlast,
             Color      = new ARGB(0x4E6C00),
             TargetId   = this.Id,
             PosA       = new Position {
                 X = radius
             }
         }, null);
         foreach (var i in enemies)
         {
             try
             {
                 if (i.HasConditionEffect(ConditionEffects.StasisImmune) || i.ObjectDesc.MaxHp > amount || i.Name == monster || i.isPet || i.isSummon || !i.ObjectDesc.Enemy || i.Name == "Pentaract Tower" || i.HasConditionEffect(ConditionEffects.Invincible) || i.HasConditionEffect(ConditionEffects.Invulnerable) || i.ObjectDesc.StasisImmune)
                 {
                     pkts.Add(new NotificationPacket
                     {
                         ObjectId = i.Id,
                         Color    = new ARGB(0x4E6C00),
                         Text     = "Immune"
                     });
                 }
                 else
                 {
                     Position pos = new Position();
                     pos.X = i.X;
                     pos.Y = i.Y;
                     Owner.LeaveWorld(i);
                     var newenemy = Resolve(obj);
                     Owner.EnterWorld(newenemy);
                     newenemy.Move(pos.X, pos.Y);
                     maximumtransforms++;
                     if (maximumtransforms == 10)
                     {
                         break;
                     }
                 }
             }
             catch
             {
                 Console.ForegroundColor = ConsoleColor.DarkBlue;
                 Console.Out.WriteLine("Crash halted - Totem error!");
                 Console.Out.WriteLine(i.Name);
                 Console.ForegroundColor = ConsoleColor.White;
             }
         }
         Owner.BroadcastPackets(pkts, null);
         t += time.thisTickTimes;
     }
     t += time.thisTickTimes;
     base.Tick(time);
 }
示例#22
0
 private bool RenderBehaviorButton(BehaviorBase behavior)
 {
     var isInBuildMode = GlobalProperties.IsInBuildMode();
     return isInBuildMode || behavior.Available;
 }
示例#23
0
 public static void RemoveBehavior(this FrameworkElement fre, BehaviorBase behavior)
 {
     Extension.GetBehaviors(fre).Remove(behavior);
 }
示例#24
0
 public void SetUp()
 {
     _b = new BehaviorBase();
 }
示例#25
0
        public static BehaviorXml ExportBehavior(BehaviorBase behavior)
        {
            if (behavior == null)
            {
                return(null);
            }

            var details = new BehaviorXml
            {
                Effect = behavior.Effect
            };

            var type = behavior.GetType();

            var attribute = type.GetCustomAttribute <BehaviorAttribute>();

            if (attribute == null)
            {
                throw new Exception($"Invalid behavior: {behavior.GetType()}");
            }

            details.Type = (uint)attribute.Template;

            var properties = new List <ParameterXml>();

            foreach (var property in type.GetProperties())
            {
                if (property.Name == "Effect")
                {
                    continue;
                }

                var info = property.GetCustomAttribute <ParameterAttribute>();

                if (info == null)
                {
                    continue;
                }

                var propertyDetails = new ParameterXml
                {
                    Name = info.Name
                };

                if (property.PropertyType == typeof(BehaviorBase))
                {
                    propertyDetails.Behavior = true;

                    propertyDetails.Next = ExportBehavior(property.GetValue(behavior) as BehaviorBase);
                }
                else if (property.PropertyType == typeof(bool))
                {
                    propertyDetails.Value = (bool)property.GetValue(behavior) ? 1 : 0;
                }
                else
                {
                    propertyDetails.Value = (float)Convert.ChangeType(
                        property.GetValue(behavior) ?? 0f,
                        typeof(float)
                        );
                }

                properties.Add(propertyDetails);
            }

            details.Parameters = properties.ToArray();

            behavior.Export(details);

            return(details);
        }
示例#26
0
 public CellGroup(Cell cell, BehaviorBase behavior, double gridSize) : this(cell, gridSize)
 {
     this.Behaviors.Add(behavior);
 }
示例#27
0
 public CellGroup(List <Cell> cells, BehaviorBase behavior, double gridSize) : this(cells, gridSize)
 {
     this.Behaviors.Add(behavior);
 }
示例#28
0
 public static Address Actor(BehaviorBase behavior, Theater theater)
 {
     return theater.CreateActor(behavior);
 }
示例#29
0
        /// <summary>
        /// compose behaviors and load them to dispatcher for execution
        /// </summary>
        /// <param name="compType"></param>
        public void produce(BehaviorCompositionType compType)
        {
            Debug.WriteLine("BehaviorFactory: produce() : " + compType);

            // close all running tasks before composing new behavior set:
            subsumptionDispatcher.Close();
            while (subsumptionDispatcher.ActiveTasksCount > 0)
            {
                subsumptionDispatcher.Process();
            }

            Debug.WriteLine("BehaviorFactory: produce() : all dispatcher tasks closed, creating new combo '" + compType + "'");

            isFinishedFW = false;

            switch (compType)
            {
            case BehaviorCompositionType.CruiseAndStop:

                //dispatcher.Dispatch(new BehaviorCruise(driveGeometry) {
                //    name = "BehaviorCruise",
                //    speaker = this.speaker
                //});

                //dispatcher.Dispatch(new BehaviorGoToGoal(driveGeometry)
                //{
                //    name = "BehaviorGoToGoal",
                //    speaker = this.speaker
                //});

                //dispatcher.Dispatch(new BehaviorGoToPixy(driveGeometry)
                //{
                //    name = "BehaviorGoToPixy",
                //    speaker = this.speaker
                //});

                subsumptionDispatcher.Dispatch(new BehaviorGoToAngle(driveGeometry, 10.0d, 5.0d)
                {
                    name    = "BehaviorGoToAngle",
                    speaker = this.speaker
                });

                subsumptionDispatcher.Dispatch(new BehaviorAvoidObstacles(driveGeometry)
                {
                    name    = "BehaviorAvoidObstacles",
                    speaker = this.speaker
                });

                subsumptionDispatcher.Dispatch(new BehaviorFollowWall(driveGeometry)
                {
                    name                = "BehaviorFollowWall",
                    speaker             = this.speaker,
                    cruiseSpeed         = 15.0d,
                    avoidanceTurnFactor = 50.0d,
                    //distanceToWallMeters = 0.17d,
                    //distanceToWallMeters = 0.25d,
                    //BehaviorDeactivateCondition = bd => { return BehaviorBase.getCoordinatorData().EnablingRequest.StartsWith("Escape"); },
                    //BehaviorTerminateCondition = bd => { return bd.sensorsData.IrRearMeters < 0.2d; }
                });

                subsumptionDispatcher.Dispatch(new BehaviorStopPlucky()
                {
                    name               = "BehaviorStop",
                    speaker            = this.speaker,
                    tresholdStopMeters = 0.4d
                });

                subsumptionDispatcher.Dispatch(new BehaviorBackAndTurn(driveGeometry)
                {
                    name    = "Escape",
                    speaker = this.speaker,
                    BehaviorActivateCondition   = bd => { return(BehaviorBase.getCoordinatorData().EnablingRequest.StartsWith("Escape")); },
                    BehaviorDeactivateCondition = bd => { return(true); },     // deactivate after one cycle
                    BehaviorTerminateCondition  = bd => { return(false); }     // do not terminate
                });

                subsumptionDispatcher.Dispatch(new BehaviorAmIStuck()
                {
                    name    = "BehaviorAmIStuck",
                    speaker = this.speaker
                });

                BehaviorBase.getCoordinatorData().ClearEnablingRequest();
                BehaviorBase.getCoordinatorData().ClearGrabbingBehavior();
                break;

            case BehaviorCompositionType.AroundTheBlock:

                BehaviorFollowWall bfw = new BehaviorFollowWall(driveGeometry)
                {
                    name                 = "BehaviorFollowWall",
                    speaker              = this.speaker,
                    cruiseSpeed          = 15.0d,
                    avoidanceTurnFactor  = 50.0d,
                    distanceToWallMeters = 0.17d,
                    //BehaviorDeactivateCondition = bd => { return BehaviorBase.getCoordinatorData().EnablingRequest.StartsWith("Escape"); },
                    //BehaviorTerminateCondition = bd => { return bd.sensorsData.IrRearMeters < 0.2d; }
                };

                bfw.BehaviorDeactivateCondition = bd =>
                {
                    isFinishedFW =
                        //(DateTime.Now - bfw.FiredOnTimestamp).TotalSeconds > 5.0d
                        (DateTime.Now - activatedFW).TotalSeconds > 5.0d
                        //&& Math.Abs(DirectionMath.to180(bd.sensorsData.CompassHeadingDegrees - initialCompassHeadingDegrees)) < 5.0d;

                        && Math.Abs(bd.robotPose.XMeters) < 0.08d &&    // forward
                        Math.Abs(bd.robotPose.YMeters) < 0.25d;         // sides

                    return(isFinishedFW);
                };

                bfw.BehaviorActivateCondition = bd => {
                    if (isFinishedFW)
                    {
                        return(false);
                    }

                    double irLeftMeters     = bd.sensorsData.IrLeftMeters;
                    double sonarLeftMeters  = bd.sensorsData.RangerFrontLeftMeters;
                    double irRightMeters    = bd.sensorsData.IrRightMeters;
                    double sonarRightMeters = bd.sensorsData.RangerFrontRightMeters;

                    double activateDistanceToWallMeters = bfw.distanceToWallMeters * 1.5d;

                    if (irLeftMeters < activateDistanceToWallMeters || (irLeftMeters < bfw.distanceToWallMeters && sonarLeftMeters < bfw.distanceToWallMeters))
                    {
                        bfw.fireOnLeft = true;
                    }

                    if (irRightMeters < activateDistanceToWallMeters || (irRightMeters < bfw.distanceToWallMeters && sonarRightMeters < bfw.distanceToWallMeters))
                    {
                        bfw.fireOnRight = true;
                    }

                    if ((bfw.fireOnLeft || bfw.fireOnRight) && bd.sensorsData.CompassHeadingDegrees.HasValue)
                    {
                        // remember the initial CompassHeadingDegrees:
                        initialCompassHeadingDegrees = bd.sensorsData.CompassHeadingDegrees.Value;
                        activatedFW = DateTime.Now;
                    }

                    return(bfw.fireOnLeft || bfw.fireOnRight);
                };
                subsumptionDispatcher.Dispatch(bfw);

                subsumptionDispatcher.Dispatch(new BehaviorStopPlucky()
                {
                    name    = "BehaviorStop",
                    speaker = this.speaker,
                    BehaviorActivateCondition = bd => { return(true); }
                });

                break;

            case BehaviorCompositionType.ChaseColorBlob:

                subsumptionDispatcher.Dispatch(new BehaviorGoToPixy(driveGeometry)
                {
                    name    = "BehaviorGoToPixy",
                    speaker = this.speaker
                });

                subsumptionDispatcher.Dispatch(new BehaviorGoToAngle(driveGeometry, 100.0d, 100.0d)
                {
                    name    = "BehaviorGoToAngle",
                    speaker = this.speaker
                });

                subsumptionDispatcher.Dispatch(new BehaviorStopPlucky()
                {
                    name               = "BehaviorStop",
                    speaker            = this.speaker,
                    tresholdStopMeters = 0.8d,
                    //BehaviorActivateCondition = bd => { return bd.driveInputs != null && bd.sensorsData != null && TooClose(bd); }
                    //BehaviorActivateCondition = bd => { return false; }
                });

                //subsumptionDispatcher.Dispatch(new BehaviorBackAndTurn(driveGeometry)
                //{
                //    name = "Escape",
                //    speaker = this.speaker,
                //    BehaviorActivateCondition = bd => { return BehaviorBase.getCoordinatorData().EnablingRequest.StartsWith("Escape"); },
                //    BehaviorDeactivateCondition = bd => { return true; },  // deactivate after one cycle
                //    BehaviorTerminateCondition = bd => { return false; }   // do not terminate
                //});

                break;

            case BehaviorCompositionType.RouteFollowing:

                subsumptionDispatcher.Dispatch(new BehaviorRouteFollowing(driveGeometry, this.speaker, TrackFileName)
                {
                    name = "BehaviorRouteFollowing"
                });

                subsumptionDispatcher.Dispatch(new BehaviorGoToAngle(driveGeometry, 100.0d, 100.0d)
                {
                    name    = "BehaviorGoToAngle",
                    speaker = this.speaker
                });

                subsumptionDispatcher.Dispatch(new BehaviorStopPlucky()
                {
                    name               = "BehaviorStop",
                    speaker            = this.speaker,
                    tresholdStopMeters = 0.6d,
                    //BehaviorActivateCondition = bd => { return bd.driveInputs != null && bd.sensorsData != null && TooClose(bd); }
                    //BehaviorActivateCondition = bd => { return false; }
                });

                subsumptionDispatcher.Dispatch(new BehaviorBackAndTurn(driveGeometry)
                {
                    name    = "Escape",
                    speaker = this.speaker,
                    BehaviorActivateCondition   = bd => { return(BehaviorBase.getCoordinatorData().EnablingRequest.StartsWith("Escape")); },
                    BehaviorDeactivateCondition = bd => { return(true); },     // deactivate after one cycle
                    BehaviorTerminateCondition  = bd => { return(false); }     // do not terminate
                });

                break;

            case BehaviorCompositionType.JoystickAndStop:

                subsumptionDispatcher.Dispatch(new BehaviorControlledByJoystick(driveGeometry)
                {
                    name    = "BehaviorControlledByJoystick",
                    speaker = this.speaker
                });

                //subsumptionDispatcher.Dispatch(new BehaviorAvoidObstacles(driveGeometry)
                //{
                //    name = "BehaviorAvoidObstacles",
                //    speaker = this.speaker
                //});

                //subsumptionDispatcher.Dispatch(new BehaviorStop()
                //{
                //    name = "BehaviorStop",
                //    speaker = this.speaker
                //});
                break;

            case BehaviorCompositionType.Escape:

                subsumptionDispatcher.Dispatch(new BehaviorBackAndTurn(driveGeometry)
                {
                    name    = "Escape",
                    speaker = this.speaker,
                    BehaviorActivateCondition   = bd => { return(true); },
                    BehaviorDeactivateCondition = bd => { return(true); },     // deactivate after one cycle
                    // BehaviorTerminateCondition = new BehaviorTerminateConditionDelegate(delegate(IBehaviorData bd) { return true; })
                    BehaviorTerminateCondition = bd => { return(true); }       // terminate after first drive-turn cycle
                });

                BehaviorBase.getCoordinatorData().EnablingRequest = "Escape";       // set it immediately to see the escape action

                subsumptionDispatcher.Dispatch(new BehaviorStopPlucky()
                {
                    name    = "BehaviorStop",
                    speaker = this.speaker
                });
                break;
            }
        }
 public void RemoveSelection(BehaviorBase behavior)
 {
     if (IsNameSelected(behavior.Name))
     {
         RemoveSelection(behavior.Name);
     }
 }
 private void RemoveActivation(BehaviorBase behavior)
 {
     if (behavior != null)
     {
         behavior.Active = false;
     }
 }
 private void ApplyActivation(BehaviorBase behavior)
 {
     if (behavior != null)
     {
         behavior.Active = true;
     }
 }
示例#33
0
 public static void AddBehavior(this FrameworkElement fre, BehaviorBase behavior)
 {
     Extension.GetBehaviors(fre).Add(behavior);
 }
示例#34
0
文件: Oryx.cs 项目: ethus3h/LR-v1
        private void EnsurePopulation()
        {
            RecalculateEnemyCount();
            var state = new int[12];
            var diff  = new int[12];
            var c     = 0;

            for (var i = 0; i < state.Length; i++)
            {
                if (enemyCounts[i] > enemyMaxCounts[i] * 1.5) //Kill some
                {
                    state[i] = 1;
                    diff[i]  = enemyCounts[i] - enemyMaxCounts[i];
                    c++;
                }
                else if (enemyCounts[i] < enemyMaxCounts[i] * realmevent) //Add some (realm events percent by dev)
                {
                    state[i] = 2;
                    diff[i]  = enemyMaxCounts[i] - enemyCounts[i];
                }
                else
                {
                    state[i] = 0;
                }
            }
            foreach (var i in world.Enemies) //Kill
            {
                var   idx  = (int)i.Value.Terrain - 1;
                float dist = 10;
                if (idx == -1 || state[idx] == 0 ||
                    BehaviorBase.GetNearestEntity(i.Value, ref dist, true) != null ||
                    diff[idx] == 0)
                {
                    continue;
                }

                if (state[idx] == 1)
                {
                    world.LeaveWorld(i.Value);
                    diff[idx]--;
                    if (diff[idx] == 0)
                    {
                        c--;
                    }
                }
                if (c == 0)
                {
                    break;
                }
            }

            int w = world.Map.Width, h = world.Map.Height;

            for (var i = 0; i < state.Length; i++) //Add
            {
                if (state[i] != 2)
                {
                    continue;
                }
                var x = diff[i];
                var t = (WmapTerrain)(i + 1);
                for (var j = 0; j < x;)
                {
                    var objType = GetRandomObjType(spawn[t].Item2);
                    if (objType == 0)
                    {
                        continue;
                    }

                    j += Spawn(XmlDatas.ObjectDescs[objType], t, w, h);
                }
            }
            RecalculateEnemyCount();

            GC.Collect();
        }
    public void SelectBehavior(BehaviorBase behavior)
    {
        if (behavior == null)
        {
            return;
        }
        if (IsNameSelected(behavior.Name))
        {
            return;
        }

        if (behavior.BehaviorType == BehaviorTypes.Actions)
        {
            SelectedAction = behavior as Action;
        }
        if (behavior.BehaviorType == BehaviorTypes.Triggers)
        {
            SelectedTrigger = behavior as Trigger;
        }
    }
    public void SetPreview(string name)
    {
        var behavior = _behaviors.GetBehavior(name);
        if (behavior == null)
        {
            return;
        }

        if (_preview != null)
        {
            ClearPreview();
        }

        _preview = behavior;

        if (_preview is Action && SelectedAction != null)
        {
            _covering = SelectedAction;
            _covering.ClearUI();
        }

        if (_preview is Trigger && SelectedTrigger != null)
        {
            _covering = SelectedTrigger;
            _covering.ClearUI();
        }

        if (_preview != null)
        {
            _preview.UpdateUI(true);
        }
    }
示例#37
0
 //----------------------------------------------------------------------
 //----------------------------------------------------------------------
 public void AddBehavior(BehaviorBase sBehavior)
 {
     m_lBehaviorList.Add(sBehavior);
 }