Beispiel #1
0
        public FortificationPart(GameObject go, FortificationPart ff)
            : base(go, ff)
        {
            State       = ff.State;
            Price       = ff.Price;
            TimeToBuild = ff.TimeToBuild;
            Health      = ff.Health;
            MaxHealth   = ff.MaxHealth;

            Start();
        }
        public override void Initialize()
        {
            MyObject.DrawLast = true;
            int typeNumber = (int)MyType;

            this.interactionTexture = ResourceManager.Instance.LoadTexture(@"Textures/HUD/x_button");

            for (int i = 0; i < PART_IN_TYPE_COUNT; ++i)
            {
                GameObject fortPart = new GameObject(MyObject.UniqueID + (uint)MyObject.Name.GetHashCode() + (uint)i, MyObject.Name + "FortificationPart" + (i).ToString());

                int tN = i + TYPE_COUNT * typeNumber;

                List <Material> mMats = ResourceManager.Instance.LoadBasicMaterialsFromModel(
                    ResourceManager.Instance.LoadModel(PartModels[tN]), ResourceManager.Instance.LoadEffect(@"Effects\NormalEffect"));

                foreach (Material mat in mMats)
                {
                    mat.Glossiness = PartGlosses[tN];
                }

                MyObject.AddChild(fortPart);

                CustomModel mod = new CustomModel(fortPart, new Model[] { ResourceManager.Instance.LoadModel(PartModels[tN]), null, null }, mMats);
                fortPart.Components.Add(mod);
                fortPart.MyTransform = new Transform(fortPart, PartTranslations[tN], Vector3.Up, PartRotations[tN], PartScales[tN]);
                fortPart.MyCollider  = new BoxCollider(fortPart);
                fortPart.Tags.Add("Fortification");

                FortificationPart p = new FortificationPart(fortPart);
                p.MaxHealth   = PartHealths[tN];
                p.Health      = 0;
                p.Price       = PartPrices[tN];
                p.TimeToBuild = PartTimes[tN];
                fortPart.Components.Add(p);

                p.Initialize();

                p.State  = FortificationPart.PartState.PENDING;
                Parts[i] = p;
            }

            if (CurrentID == (int)FortificationState.STATE_EMPTY)
            {
                Parts[0].State = FortificationPart.PartState.NEXT_BUILD;
            }
            else if (CurrentID == (int)FortificationState.STATE_FIRST)
            {
                Parts[0].State  = FortificationPart.PartState.BUILT;
                Parts[0].Health = Parts[0].MaxHealth;
                Parts[1].State  = FortificationPart.PartState.NEXT_BUILD;
            }
            else if (CurrentID == (int)FortificationState.STATE_SECOND)
            {
                Parts[0].State  = FortificationPart.PartState.BUILT;
                Parts[0].Health = Parts[0].MaxHealth;
                Parts[1].State  = FortificationPart.PartState.BUILT;
                Parts[1].Health = Parts[1].MaxHealth;
                Parts[2].State  = FortificationPart.PartState.NEXT_BUILD;
            }
            else if (CurrentID == (int)FortificationState.STATE_THIRD)
            {
                Parts[0].State  = FortificationPart.PartState.BUILT;
                Parts[0].Health = Parts[0].MaxHealth;
                Parts[1].State  = FortificationPart.PartState.BUILT;
                Parts[1].Health = Parts[1].MaxHealth;
                Parts[2].State  = FortificationPart.PartState.BUILT;
                Parts[2].Health = Parts[2].MaxHealth;
            }

            triggerEnemyObj = new GameObject(MyObject.UniqueID + (uint)MyObject.Name.GetHashCode() + (uint)PART_IN_TYPE_COUNT, MyObject.Name + "FortificationTriggerEnemy");

            MyObject.AddChild(triggerEnemyObj);

            triggerEnemyObj.MyTransform          = new Transform(triggerEnemyObj);
            triggerEnemyObj.MyTransform.Position = new Vector3(0.0f, 0.0f, 2.0f);
            triggerEnemyObj.MyTransform.Scale    = 2.0f;
            triggerEnemyObj.MyCollider           = new BoxCollider(triggerEnemyObj, true);

            triggerEnemyObj.OnTriggerEnterEvent += new GameObject.OnTriggerEnterEventHandler(OnTriggerEnterEnemyHandler);
            triggerEnemyObj.OnTriggerExitEvent  += new GameObject.OnTriggerExitEventHandler(OnTriggerExitEnemyHandler);

            ///

            triggerPlayerObj = new GameObject(MyObject.UniqueID + (uint)MyObject.Name.GetHashCode() + (uint)PART_IN_TYPE_COUNT + 1, MyObject.Name + "FortificationTriggerPlayer");

            MyObject.AddChild(triggerPlayerObj);

            triggerPlayerObj.MyTransform          = new Transform(triggerPlayerObj);
            triggerPlayerObj.MyTransform.Position = new Vector3(0.0f, 0.0f, 0.0f);
            triggerPlayerObj.MyTransform.Scale    = 5.0f;
            triggerPlayerObj.MyCollider           = new SphereCollider(triggerPlayerObj, true);

            triggerPlayerObj.OnTriggerEnterEvent += new GameObject.OnTriggerEnterEventHandler(OnTriggerEnterPlayerHandler);
            triggerPlayerObj.OnTriggerExitEvent  += new GameObject.OnTriggerExitEventHandler(OnTriggerExitPlayerHandler);

            for (int i = 0; i < PART_IN_TYPE_COUNT; ++i)
            {
                triggerEnemyObj.MyCollider.IgnoredColliders.Add(Parts[i].MyObject.MyCollider);
                triggerPlayerObj.MyCollider.IgnoredColliders.Add(Parts[i].MyObject.MyCollider);
            }
            triggerEnemyObj.MyCollider.IgnoredColliders.Add(ResourceManager.Instance.CurrentScene.ObjectsDictionary[1].MyCollider);

            GameObject player = ResourceManager.Instance.CurrentScene.ObjectsDictionary[1];

            stashComponent = (HideoutStash)player.GetComponent <HideoutStash>();
            pController    = (PlayerController)player.GetComponent <PlayerController>();

            SoundEffect se = TrashSoupGame.Instance.Content.Load <SoundEffect>(@"Audio/Ambient/building");

            buildSound          = se.CreateInstance();
            buildSound.IsLooped = true;

            base.Initialize();
        }
 protected override void Start()
 {
     Parts     = new FortificationPart[PART_IN_TYPE_COUNT];
     MyType    = (FortificationType)0;
     CurrentID = -1;
 }