Exemple #1
0
 public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance aState)
 {
     Entity ai = (Entity)behaviour;
     EntityMovement em = ai.entMove;
     em.Jump(speedMin < speedMax ? Random.Range(speedMin, speedMax) : speedMin);
     ai.state = state;
 }
    public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        AIState aiState = (AIState)state;
        Entity ai = (Entity)behaviour;

        PlanetAttach pa = ai.planetAttach;
        Player player = SceneLevel.instance.player;

        //Debug.Log("side: "+pa.CheckSide(player.planetAttach));
        Vector2 prevDir = aiState.curPlanetDir;
        aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, horizontalOnly);

        bool done = true;

        //cap speed on opposite dir
        if(Vector2.Dot(prevDir, aiState.curPlanetDir) < 0.0f) {
            if(useBreakSpeed) {
                pa.velocity = prevDir*breakSpeed;
            }

            if(doneAfterNumChangeDir > 0 && aiState.counter < doneAfterNumChangeDir) {
                aiState.counter++;
            }
        }

        if(doneAfterNumChangeDir > 0) {
            done = doneAfterNumChangeDir == aiState.counter && Vector2.Dot(pa.planetDir, aiState.curPlanetDir) > 0.0f;
        }

        //pa.velocity = Vector2.zero;
        pa.accel = aiState.curPlanetDir*accel;

        return done;
    }
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        if(entityPath.Length > 0) {
            GameObject go = ((SceneController)behaviour).SearchObject(entityPath);
            if(go != null) {
                Entity e = go.GetComponent<Entity>();
                if(e != null) {
                    if(e.stats != null) {
                        if(amount == -1) {
                            if(e.stats.curHP > 1) {
                                e.stats.ApplyDamage(e.stats.curHP-1);
                            }
                        }
                        else {
                            e.stats.ApplyDamage(amount);
                        }
                    }

                    e.action = action;
                }
                else {
                    Debug.LogWarning("Not an entity: "+entityPath);
                }
            }
            else {
                Debug.LogWarning("Path not found: "+entityPath);
            }
        }
    }
Exemple #4
0
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity ai = (Entity)behaviour;
        PlanetAttach pa = ai.planetAttach;
        AIState aiState = (AIState)state;

        float speed = speedMin < speedMax ? Random.Range(speedMin, speedMax) : speedMin;
        if(speed > 0) {
            if(followPlayer) {
                Player player = SceneLevel.instance.player;

                aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, followPlayerHorizontal);
            }
            else if(!useDir) {
                aiState.curPlanetDir = Util.Vector2DRot(new Vector2(1, 0), angle*Mathf.Deg2Rad);
            }

            pa.velocity = aiState.curPlanetDir*speed;

            ai.action = Entity.Action.move;
        }
        else {
            pa.velocity = Vector2.zero;

            ai.action = Entity.Action.idle;
        }

        if(resetAccel) {
            pa.accel = Vector2.zero;
        }
    }
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance aState)
    {
        Entity ai = (Entity)behaviour;
        AIState aiState = (AIState)aState;

        ai.state = state;

        Vector2 src = ai.transform.position;
        Vector2 dest = Player.instance.transform.position;

        switch(type) {
        case Type.xOnly:
            dest.y = src.y;
            break;

        case Type.yOnly:
            dest.x = src.x;
            break;
        }

        Vector2 dir = dest - src;
        float dist = dir.magnitude;
        dir = dir/dist;

        float spd = minSpeed < maxSpeed ? Random.Range(minSpeed, maxSpeed) : minSpeed;
        ai.entMove.velocity = dir*spd;

        aiState.d = dist/spd;
    }
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Main.instance.cameraController.mode = mode;

        if(attachToPath.Length > 0) {
            GameObject go = ((SceneController)behaviour).SearchObject(attachToPath);
            if(go != null) {
                Main.instance.cameraController.attach = go.transform;
            }
            else {
                Debug.LogWarning("Path not found: "+attachToPath);
            }
        }
        else if(attachToWaypoint.Length > 0) {
            Transform t = WaypointManager.instance.GetWaypoint(attachToWaypoint);
            if(t != null) {
                Main.instance.cameraController.attach = t;
            }
            else {
                Debug.LogWarning("Can't find waypoint: "+attachToWaypoint);
            }
        }

        if(immediate) {
            Main.instance.cameraController.CancelMove();
        }
    }
        public void SetUp()
        {
            _gatingSequence = new Sequence(Sequencer.InitialCursorValue);

            _sequencer = new Sequencer(new SingleThreadedClaimStrategy(BufferSize), new SleepingWaitStrategy());
            _sequencer.SetGatingSequences(_gatingSequence);
        }
Exemple #8
0
        public void AssertRepetitionProgressionPattern()
        {
            const int pauseAfter = 20;
            const int start = 1;

            Func<int, int> progression = x => x + 1;

            var repetitionExpectedResultPair = new Dictionary<int, string>
                                                   {
                                                       {1, "1,2,3,4,5,6,7,8,9,10,11,12"},
                                                       {2, "1,1,2,2,3,3,4,4,5,5,6,6"},
                                                       {4, "1,1,1,1,2,2,2,2,3,3,3,3"}
                                                   };

            foreach (var pair in repetitionExpectedResultPair)
            {
                var repititions = pair.Key;
                var expected = pair.Value;

                var e = new Sequencer<int>(start, repititions, pauseAfter, progression);
                var results = new List<int>();
                const int noOfElements = 12;

                for (var i = 0; i < noOfElements; i++)
                {
                    e.MoveNext();
                    var next = e.Current;
                    results.Add(next);
                }
                var distances = string.Join(",", results.ConvertAll(x => x.ToString()).ToArray());
                Assert.AreEqual(expected, distances);
            }
        }
Exemple #9
0
 public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
 {
     Entity ai = (Entity)behaviour;
     PlanetAttach pa = ai.planetAttach;
     pa.Jump(speedMin < speedMax ? Random.Range(speedMin, speedMax) : speedMin);
     ai.action = Entity.Action.jump;
 }
        public void CreateRecipes()
        {
            //Init sequencer
            seq = new Sequencer();

            //Recipe 1
            TaskData t1 = new TaskData(1, 15, false);
            TaskData t2 = new TaskData(2, 5, true);
            TaskData t3 = new TaskData(3, 2, true);
            TaskData t4 = new TaskData(4, 13, true);
            TaskData t5 = new TaskData(5, 20, false);
            TaskData t6 = new TaskData(6, 4, true);
            TaskData t7 = new TaskData(7, 3, true);
            TaskData t8 = new TaskData(8, 10, false);
            TaskData t9 = new TaskData(9, 1, true);
            TaskData t10 = new TaskData(10, 3, true);

            t10.addPrereq(t9);
            t10.addPrereq(t8);
            t8.addPrereq(t7);
            t7.addPrereq(t6);
            t9.addPrereq(t5);
            t5.addPrereq(t4);
            t4.addPrereq(t3);
            t3.addPrereq(t2);
            t2.addPrereq(t1);

            r1 = new RecipeData();
            r1.finalStep = t10;

            //Recipe 2
            TaskData t11 = new TaskData(11, 10, false);
            TaskData t12 = new TaskData(12, 6, true);
            TaskData t13 = new TaskData(13, 4, true);
            TaskData t14 = new TaskData(14, 15, true);

            t14.addPrereq(t13);
            t13.addPrereq(t12);
            t12.addPrereq(t11);

            r2 = new RecipeData();
            r2.finalStep = t14;

            //Recipe 3
            TaskData t15 = new TaskData(15, 9, false);
            TaskData t16 = new TaskData(16, 3, true);
            TaskData t17 = new TaskData(17, 5, true);
            TaskData t18 = new TaskData(18, 4, true);
            TaskData t19 = new TaskData(19, 1, true);
            TaskData t20 = new TaskData(20, 15, false);

            t20.addPrereq(t19);
            t19.addPrereq(t18);
            t19.addPrereq(t17);
            t19.addPrereq(t16);
            t19.addPrereq(t15);

            r3 = new RecipeData();
            r3.finalStep = t20;
        }
Exemple #11
0
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity ai = (Entity)behaviour;
        PlanetAttach pa = ai.planetAttach;
        Player player = SceneLevel.instance.player;

        ((AIState)state).curPlanetDir = pa.GetDirTo(player.planetAttach, horizontalOnly);
    }
    //do clean ups here, don't set any states dependent from outside
    public override void Finish(MonoBehaviour behaviour, Sequencer.StateInstance aState)
    {
        Entity ai = (Entity)behaviour;
        ai.state = endState;

        if(ai.entMove != null) {
            ai.entMove.velocity = Vector2.zero;
        }
    }
Exemple #13
0
 void OnNextPulse(Sequencer sequencer)
 {
     if (sequencer.CurrentPulse % 4 == 0) {
       nextNote = 12.0f * (sequencer.CurrentPulse % 32) / 4.0f;
     } else if (sequencer.CurrentPulse % 2 == 0 &&
             RandomNumber.NextFloat() < 0.1f) {
       nextNote = 12.0f * RandomNumber.NextInt(0, 8);
     }
 }
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        state.counter = 0;

        Player p = ((SceneLevel)behaviour).player;
        p.throwCallback = delegate(Player player) {
            state.counter = 1;
        };
    }
        public ProcessingSequenceBarrier(Sequencer sequencer, 
                                         IWaitStrategy waitStrategy, 
                                         Sequence cursorSequence, 
                                         ISequence[] dependentSequences)
        {
            _waitStrategy = waitStrategy;
            _cursorSequence = cursorSequence;
            _sequencer = sequencer;

            _dependentSequence = 0 == dependentSequences.Length ? (ISequence)cursorSequence : new FixedSequenceGroup(dependentSequences);
        }
    public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        bool done = true;

        Entity e = ((SceneController.StateData)state).entity;
        if(e != null) {
            e.SendMessage("OnSceneCounterCheck", state, SendMessageOptions.RequireReceiver);
            done = state.counter == counter;
        }

        return done;
    }
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        SceneLevel.instance.IncWave();

        HUDAnnounce announce = UIManager.instance.hud.announce;

        announce.state = HUDAnnounce.State.Blink;
        announce.message = isBossAnnounce ? bossString : SceneLevel.instance.GetWaveString();
        announce.color = Color.white;

        state.counter = 0;
    }
 public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
 {
     if(entityPath.Length > 0) {
         GameObject go = ((SceneController)behaviour).SearchObject(entityPath);
         if(go != null) {
             go.SendMessage("OnSceneActivate", activate, SendMessageOptions.DontRequireReceiver);
         }
         else {
             Debug.LogWarning("Path not found: "+entityPath);
         }
     }
 }
    public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        SceneController.StateData dat = (SceneController.StateData)state;

        bool done = true;

        if(dat.entity != null) {
            done = dat.entity.action == action;
        }

        return done;
    }
Exemple #20
0
    public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity ai = (Entity)behaviour;
        PlanetAttach pa = ai.planetAttach;

        bool done = pa.isGround;

        if(done && actOnLand != Entity.Action.none) {
            ai.action = actOnLand;
        }

        return pa.isGround;
    }
Exemple #21
0
    public override bool Update(MonoBehaviour behaviour, Sequencer.StateInstance aState)
    {
        Entity ai = (Entity)behaviour;
        EntityMovement em = ai.entMove;

        bool done = em.isGround;

        if(done && endState != Entity.State.NumState) {
            ai.state = endState;
        }

        return done;
    }
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance aiState)
    {
        HUDAnnounce ha = UIManager.instance.hud.announce;

        ha.state = state;

        if(state != HUDAnnounce.State.None) {
            if((state != HUDAnnounce.State.FadeOut && state != HUDAnnounce.State.FadeScaleOut) || message.Length > 0) {
                ha.color = new Color(((float)colorR)/255.0f, ((float)colorG)/255.0f, ((float)colorB)/255.0f);
                ha.message = message;
            }
        }
    }
Exemple #23
0
 void Start()
 {
     sequencer = GetComponent<Sequencer>();
     sequencer.tempo = tempo;
     sequencer.OnNextBar += OnNextBar;
     cameraController = GetComponent<CameraController>();
     monster =
       GameObject.Instantiate(monsterPrefab).GetComponent<MonsterController>();
     monster.speechGui = monsterSpeechGui;
     monster.SetLeftEnd(cameraController.ScreenLeft);
     monster.speakSpeed = 8.0f / tempo;
     line = GameObject.Instantiate(groundPrefab).GetComponent<LineController>();
     line.SetStartPoint(monster.GetRightEnd());
     line.SetLength(0.5f * cameraController.ScreenSize - monster.GetRightEnd());
 }
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        SceneLevel sl = SceneLevel.instance;

        Player player = sl.player;

        Transform t = EntityManager.instance.Spawn(type, name, null, null, useFX);

        if(t != null) {
            Vector2 playerPos = player.planetAttach.planetPos;

            Vector2 pos = sl.planet.body.ConvertToWorldPos(new Vector2(playerPos.x+x, playerPos.y+y));

            t.position = new Vector3(pos.x, pos.y, t.position.z);
            t.GetComponentInChildren<PlanetAttachStatic>().RefreshPos();
        }
    }
Exemple #25
0
 void OnNextBar(Sequencer sequencer)
 {
     if(countdown > 0) {
       countdown--;
       return;
     }
     string speech = monsterLines[(int)Mathf.Min(monsterLines.Length - 1,
     currentMonsterLine)];
     if (currentMonsterLine > 4 && speech.Length > 0
     && RandomNumber.NextFloat() < 0.2f) {
       speech = monsterRandomLinebreaks[RandomNumber.NextInt(0,
     monsterRandomLinebreaks.Length)];
     } else {
       currentMonsterLine++;
     }
     monster.Speak(speech);
 }
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        if(type.Length > 0) {
            System.Type theType = System.Type.GetType(type);

            Component[] comps;
            if(fromScene) {
                comps = ((SceneController)behaviour).GetComponentsInChildren(theType);
            }
            else {
                comps = EntityManager.instance.GetComponentsInChildren(theType);
            }

            foreach(Component c in comps) {
                c.SendMessage("OnSceneActivate", activate, SendMessageOptions.DontRequireReceiver);
            }
        }
    }
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity ai = (Entity)behaviour;
        EntityMovement em = ai.entMove;

        float speed = speedMin < speedMax ? Random.Range(speedMin, speedMax) : speedMin;
        if(speed > 0) {
            em.velocity.x = toPlayer ? Player.instance.transform.position.x < ai.transform.position.x ? -speed : speed : speed;
            em.velocity.y = 0;

            ai.state = Entity.State.move;
        }
        else {
            em.velocity = Vector2.zero;

            ai.state = Entity.State.idle;
        }
    }
 public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
 {
     if(entityPath.Length > 0) {
         GameObject go = ((SceneController)behaviour).SearchObject(entityPath);
         if(go != null) {
             Entity e = go.GetComponent<Entity>();
             if(e != null) {
                 ((SceneController.StateData)state).entity = e;
             }
             else {
                 Debug.LogWarning("Not an entity: "+entityPath);
             }
         }
         else {
             Debug.LogWarning("Path not found: "+entityPath);
         }
     }
 }
Exemple #29
0
    public void Start(MonoBehaviour behaviour, Sequencer.StateInstance stateData, string stateName)
    {
        if(stateName == null) {
            stateName = sequenceDefaultState;
        }

        mCurState = stateName;

        if(!string.IsNullOrEmpty(stateName)) {
            if(mSequences != null) {

                Sequencer seq;
                if(mSequences.TryGetValue(stateName, out seq)) {
                    behaviour.StartCoroutine(seq.Go(stateData, behaviour));
                }
                else {
                    Debug.LogError("State not found: "+stateName, behaviour);
                }
            }
        }
    }
Exemple #30
0
    public override void Start(MonoBehaviour behaviour, Sequencer.StateInstance state)
    {
        Entity ai = (Entity)behaviour;
        PlanetAttach pa = ai.planetAttach;
        AIState aiState = (AIState)state;

        if(accel > 0) {
            if(usePlayerDir) {
                Player player = SceneLevel.instance.player;

                aiState.curPlanetDir = pa.GetDirTo(player.planetAttach, horizontalOnly);
            }
            else if(!useDir) {
                aiState.curPlanetDir = Util.Vector2DRot(new Vector2(1, 0), angle*Mathf.Deg2Rad);
            }

            pa.accel = aiState.curPlanetDir*accel;
        }
        else {
            pa.accel = Vector2.zero;
        }
    }