예제 #1
0
        private void CreateAi(MobType mobType)
        {
            Func <CreatureState>   getter = () => AttachedObject.GetValue(CreatureStateProperty);
            Action <CreatureState> setter = v => AttachedObject.SetLocalValue(CreatureStateProperty, v);
            CreatureAi             ai;

            switch (mobType)
            {
            case Entities.MobType.Chicken:
                ai = new AiChicken(getter, setter);
                break;

            case Entities.MobType.Cow:
                ai = new AiCow(getter, setter);
                break;

            case Entities.MobType.Creeper:
                ai = new AiCreeper(getter, setter);
                break;

            case Entities.MobType.Pig:
                ai = new AiPig(getter, setter);
                break;

            case Entities.MobType.Sheep:
                ai = new AiSheep(getter, setter);
                break;

            case Entities.MobType.Skeleton:
                ai = new AiSkeleton(getter, setter);
                break;

            case Entities.MobType.Spider:
                ai = new AiSpider(getter, setter);
                break;

            case Entities.MobType.Squid:
                // TODO new ai for squid
                ai = new AiChicken(getter, setter);
                break;

            case Entities.MobType.Zombie:
                ai = new AiZombie(getter, setter);
                break;

            default:
                // TODO add more ai
                Logger.LogWarning("AI of this mob has not been implemented: {0}.", mobType);
                ai = null;
                break;
            }

            _ai = ai;
        }
예제 #2
0
        async Task IHandle <SpawnMob> .Handle(SpawnMob message)
        {
            Func <CreatureState>   getter = () => AttachedObject.GetValue(CreatureStateProperty);
            Action <CreatureState> setter = v => AttachedObject.SetLocalValue(CreatureStateProperty, v).Wait();
            CreatureAi             ai;

            switch (message.MobType)
            {
            case MobType.Chicken:
                ai = new AiChicken(getter, setter);
                break;

            case MobType.Cow:
                ai = new AiCow(getter, setter);
                break;

            case MobType.Creeper:
                ai = new AiCreeper(getter, setter);
                break;

            case MobType.Pig:
                ai = new AiPig(getter, setter);
                break;

            case MobType.Sheep:
                ai = new AiSheep(getter, setter);
                break;

            case MobType.Skeleton:
                ai = new AiSkeleton(getter, setter);
                break;

            case MobType.Squid:
                // TODO new ai for squid
                ai = new AiChicken(getter, setter);
                break;

            case MobType.Zombie:
                ai = new AiZombie(getter, setter);
                break;

            default:
                // TODO add more ai
                throw new NotImplementedException("AI of this mob has not been implemented.");
            }

            await AttachedObject.SetLocalValue(AiTypeProperty, ai);
        }