Пример #1
0
        public void ParseTraps(Room roomobj, XElement roomxml, XDocument doc)
        {
            XName trapsName = XName.Get("traps", doc.Root.Name.NamespaceName);

            XElement        traps    = roomxml.Element(trapsName);
            List <XElement> trapList = traps.Elements("trap").ToList();

            foreach (XElement trap in trapList)
            {
                XElement xloc = trap.Element("xloc");
                XElement yloc = trap.Element("yloc");
                XElement xdir = trap.Element("xdir");
                XElement ydir = trap.Element("ydir");

                float x = float.Parse(xloc.Value);
                float y = float.Parse(yloc.Value);

                int xdirection = (int)float.Parse(xdir.Value);
                int ydirection = (int)float.Parse(ydir.Value);

                Vector2 truePos = RoomUtilities.CalculateBlockCenter(roomobj.RoomPos, new Vector2(x, y));

                ITrap trapAdd = CreateTrap(truePos, new Vector2(xdirection, ydirection));
                roomobj.AddTrap(trapAdd);
            }
        }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (isActivated)
        {
            timerRespawn += Time.deltaTime;
            if (timerRespawn >= timerRespawnLimit)
            {
                timerRespawn = 0;
                // Lançar flechas
                GameObject gameObj = (GameObject)Instantiate(
                    trapPrefab.gameObject,
                    transform.position,
                    Quaternion.identity
                    );

                ITrap trap = gameObj.GetComponent <ITrap>();
                trap.Begin();
                trap.IsActivated = true;
                trap.Player      = player;
                trap.Direction   = direction;
                if (frequencyZAxis)
                {
                    trap.transform.rotation = rotation;
                }

                if (!trap.IsRespawn)
                {
                    isActivated = false;
                }
            }
        }
    }
Пример #3
0
        protected IEnumerator TweakTrapOverTime(ITrap trap)
        {
            double tweakStart = WorldClock.AdjustedRealTime;
            double tweakUntil = tweakStart + 10f;

            while (WorldClock.AdjustedRealTime < tweakUntil)
            {
                mNormalizedTweakTimeSoFar = (float)((WorldClock.AdjustedRealTime - tweakStart) / (tweakUntil - tweakStart));
                if (mCancelled || trap == null)
                {
                    yield break;
                }
                yield return(null);
            }
            if (mProgressDialog != null)
            {
                mProgressDialog.Finish();
            }
            if (trap != null)
            {
                GUI.GUIManager.PostSuccess("You have increased this trap's chance of success");
                trap.SkillOnSet = Mathf.Clamp01(trap.SkillOnSet + 0.15f);
            }
            yield break;
        }
Пример #4
0
    private GameObject FindTarget()
    {
        GameObject foundObject = null;

        Collider[] hitColliders = Physics.OverlapSphere(transform.position, m_DetectionRange);
        int        i            = 0;

        float distanceToClosestTrap = float.MaxValue;

        while (i < hitColliders.Length)
        {
            ITrap foundTrap = hitColliders[i].GetComponent(typeof(ITrap)) as ITrap;
            if (foundTrap != null)
            {
                if (foundTrap.GetTrapState() != TrapState.IDLE)
                {
                    i++;
                    continue;
                }

                float distanceToTrap = (foundTrap.GetWorldPosition() - transform.position).sqrMagnitude;

                if (distanceToTrap < distanceToClosestTrap)
                {
                    distanceToClosestTrap = distanceToTrap;
                    foundObject           = hitColliders[i].gameObject;
                }
            }
            i++;
        }

        return(foundObject);
    }
Пример #5
0
 protected override void UseStart(bool forceSuccess)
 {
     if (LastSkillFlavor == ImproveTrapFlavor)
     {
         //see if we can improve it any more
         ITrap     trap      = null;
         WaterTrap waterTrap = null;
         LandTrap  landTrap  = null;
         if (LastSkillTarget.worlditem.Is <LandTrap>(out landTrap))
         {
             trap = landTrap;
         }
         if (LastSkillTarget.worlditem.Is <WaterTrap>(out waterTrap))
         {
             trap = waterTrap;
         }
         if (trap != null)
         {
             if (trap.SkillOnSet >= 0.95f)
             {
                 GUI.GUIManager.PostWarning("This trap's setting can't be improved further");
                 return;
             }
             mProgressDialogMessage = "Tweaking Trap...";
             GetProgressDialog();
             StartCoroutine(TweakTrapOverTime(trap));
         }
     }
     else
     {
         base.UseStart(forceSuccess);
     }
 }
Пример #6
0
 public Room(int number, string sign)
 {
     this.Number = number;
     this.Sign   = sign;
     this.Supply = false;
     Trap        = new TrapFree();
 }
Пример #7
0
        public static void Run(this ITrap trap, Action action)
        {
            var run = trap.StartRun();

            action();
            run.Stop();
        }
Пример #8
0
 public StandardRoom()
 {
     WasVisited = false;
     HasPillar  = false;
     Potion     = PotionFactory.MakeRandomPotion();
     Trap       = TrapFactory.MakeRandomTrap();
     Enemy      = MonsterFactory.MakeRandomMonster();
 }
Пример #9
0
        public static async Task <T> Run <T>(this ITrap trap, Func <Task <T> > func)
        {
            var run         = trap.StartRun();
            var returnValue = await func();

            run.Stop();
            return(returnValue);
        }
Пример #10
0
        public static T Run <T>(this ITrap trap, Func <T> func)
        {
            var run         = trap.StartRun();
            var returnValue = func();

            run.Stop();
            return(returnValue);
        }
Пример #11
0
 public static void TrapHitLink(Game1 game, ITrap trap, ILink link)
 {
     if (trap.CanDamage)
     {
         States.Direction knockbackDirection = DirectionResolution(trap, link);
         link.TakeDamage(knockbackDirection, trap.Damage);
     }
     trap.OnHit();
 }
Пример #12
0
        public IResult PerformCommand(IMobileObject performer, ICommand command)
        {
            IResult result = base.PerfomCommand(performer, command);

            if (result != null)
            {
                return(result);
            }

            if (command.Parameters.Count <= 0)
            {
                return(new Result("What would you like to disarm?", true));
            }

            string itemToDisarm = command.Parameters[0].ParameterValue;
            ITrap  trap         = performer.Room.Traps.FirstOrDefault(i => i.DisarmWord.Contains(itemToDisarm));

            if (trap == null)
            {
                return(new Result($"Unable to find a {command.Parameters[0].ParameterValue} trap.", true));
            }
            else
            {
                int performerRoll = GetPlayerRoll(trap, performer);
                if (performerRoll >= trap.DisarmSuccessRoll)
                {
                    performer.Room.Traps.Remove(trap);
                    return(new Result($"You successfully disarm the {itemToDisarm} trap.", false));
                }
                else
                {
                    if (trap.DisarmFailureDamage != null)
                    {
                        performer.TakeDamage(trap.DisarmFailureDamage.Dice.RollDice(), trap.DisarmFailureDamage, trap.Description);
                        if (trap.DisarmFailureMessage != null)
                        {
                            return(new Result(trap.DisarmFailureMessage, false));
                        }
                        else
                        {
                            return(new Result("You tried to disarm the trap but accidentally tripped it.", false));
                        }
                    }
                    else
                    {
                        return(new Result($"You were unable to disarm the {itemToDisarm} trap.", false));
                    }
                }
            }
        }
Пример #13
0
        //trapping skills work by accepting traps of a certain kind to update
        //if a trap object is added it will be updated until it has been unloaded or is no longer Frozen
        public void UpdateTrap(ITrap trap)
        {
            if (Traps.SafeAdd(trap))
            {
                trap.SkillUpdating   = true;
                trap.TimeLastChecked = WorldClock.AdjustedRealTime;
            }

            if (!mUpdatingTraps)
            {
                mUpdatingTraps = true;
                StartCoroutine(UpdateTraps());
            }
        }
Пример #14
0
        public void OnItemOfInterestVisit()
        {
            Visitable visitable = null;

            if (worlditem.Is <Visitable> (out visitable))
            {
                Creature  creature           = null;
                ITrap     trap               = null;
                WorldItem lastItemOfInterest = visitable.LastItemOfInterestToVisit;
                WaterTrap waterTrap          = null;
                if (lastItemOfInterest.Is <WaterTrap> (out waterTrap) && !waterTrap.Exceptions.Contains(State.NameOfFish))
                {
                    Debug.Log("Found a water trap");
                    waterTrap.IntersectingDens.SafeAdd(this);
                }
            }
        }
Пример #15
0
    private void CheckForTraps()
    {
        Vector3 checkPoint = transform.position;

        checkPoint.y = 0.5f;
        Collider[] hitColliders = Physics.OverlapSphere(checkPoint, m_DetectionRange);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            ITrap foundTrap = hitColliders[i].GetComponent(typeof(ITrap)) as ITrap;
            if (foundTrap != null)
            {
                foundTrap.TrapDetected();
            }

            i++;
        }
    }
Пример #16
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (!pressurePlateTriggered)
        {
            if (col.gameObject.tag == "Player" || col.gameObject.tag == "Enemy")
            {
                for (int i = 0; i < trapsList.Length; i++)
                {
                    ITrap iTrapObj = trapsList[i].GetComponent <ITrap>();

                    if (iTrapObj != null)
                    {
                        iTrapObj.activateTrap();
                    }
                }

                pressurePlateTriggered = true;
                oneTimeBool            = true;
                StartCoroutine(resetPressurePlate(pressurePlateDelay));
            }
        }
    }
Пример #17
0
        private int GetPlayerRoll(ITrap trap, IMobileObject performer)
        {
            switch (trap.DisarmStat)
            {
            case Stats.Stat.Charisma:
                return(GlobalReference.GlobalValues.Random.Next(performer.CharismaEffective));

            case Stats.Stat.Constitution:
                return(GlobalReference.GlobalValues.Random.Next(performer.ConstitutionEffective));

            case Stats.Stat.Dexterity:
            default:
                return(GlobalReference.GlobalValues.Random.Next(performer.DexterityEffective));

            case Stats.Stat.Intelligence:
                return(GlobalReference.GlobalValues.Random.Next(performer.IntelligenceEffective));

            case Stats.Stat.Strength:
                return(GlobalReference.GlobalValues.Random.Next(performer.StrengthEffective));

            case Stats.Stat.Wisdom:
                return(GlobalReference.GlobalValues.Random.Next(performer.WisdomEffective));
            }
        }
Пример #18
0
        public void OnItemOfInterestVisit()
        {
            //Debug.Log("On item of interest visit");
            Visitable visitable = null;

            if (worlditem.Is <Visitable>(out visitable))
            {
                Creature  creature           = null;
                ITrap     trap               = null;
                WorldItem lastItemOfInterest = visitable.LastItemOfInterestToVisit;
                LandTrap  landTrap           = null;
                WaterTrap waterTrap          = null;
                if (lastItemOfInterest.Is <LandTrap>(out landTrap) && !landTrap.Exceptions.Contains(NameOfCreature))
                {
                    //Debug.Log("Found a land trap");
                    landTrap.IntersectingDens.SafeAdd(this);
                }
                else if (lastItemOfInterest.Is <WaterTrap>(out waterTrap) && !waterTrap.Exceptions.Contains(NameOfCreature))
                {
                    //Debug.Log("Found a water trap");
                    waterTrap.IntersectingDens.SafeAdd(this);
                }
            }
        }
Пример #19
0
        protected IEnumerator UpdateTraps()
        {
            while (Traps.Count > 0)
            {
                //Debug.Log("Updating traps: " + Traps.Count.ToString());
                for (int i = Traps.LastIndex(); i >= 0; i--)
                {
                    //Debug.Log("Checking trap");
                    ITrap trap = Traps[i];
                    if (trap == null)
                    {
                        Traps.RemoveAt(i);
                    }
                    else if (trap.IsFinished || trap.Mode != TrapMode.Set)
                    {
                        trap.SkillUpdating = false;
                        Traps.RemoveAt(i);
                    }
                    else
                    {
                        //okay, the trap is set and it's not finished and it has intersecting dens
                        for (int j = trap.IntersectingDens.LastIndex(); j >= 0; j--)
                        {
                            ICreatureDen den = trap.IntersectingDens[j];
                            if (den == null || den.IsFinished)
                            {
                                trap.IntersectingDens.RemoveAt(j);
                            }
                            else if (trap.CanCatch.Count > 0 && !trap.CanCatch.Contains(den.NameOfCreature) ||
                                     trap.Exceptions.Count > 0 && trap.Exceptions.Contains(den.NameOfCreature))
                            {
                                //make sure this trap can actually catch what's in it
                                trap.IntersectingDens.RemoveAt(j);
                            }
                            else
                            {
                                //is it time to check this trap yet? is the player nearby?
                                if ((WorldClock.AdjustedRealTime - trap.TimeLastChecked) > Globals.TrappingMinimumRTCheckInterval)
                                {
                                    bool readyToCheck = true;
                                    if (trap.RequiresMinimumPlayerDistance && Vector3.Distance(Player.Local.Position, trap.Owner.tr.position) < Globals.TrappingMinimumCorpseSpawnDistance)
                                    {
                                        readyToCheck = false;
                                    }
                                    if (readyToCheck)
                                    {
                                        trap.TimeLastChecked = WorldClock.AdjustedRealTime;
                                        //odds of catching something increases over time
                                        float  oddsOfCatchingSomething = trap.SkillOnSet;
                                        double timeSinceSet            = WorldClock.AdjustedRealTime - trap.TimeSet;
                                        oddsOfCatchingSomething = Mathf.Clamp01((float)(oddsOfCatchingSomething + (Globals.TrappingOddsTimeMultiplier * timeSinceSet)));
                                        //okay, figure out how close to the den we are
                                        float distanceToCenterOfDen = Vector3.Distance(trap.Owner.tr.position, den.transform.position);
                                        float distanceToDen         = distanceToCenterOfDen - den.Radius;
                                        float trapRadius            = Skill.SkillEffectRadius(
                                            Effects.UnskilledEffectRadius,
                                            Effects.SkilledEffectRadius,
                                            Effects.MasteredEffectRadius,
                                            trap.SkillOnSet,                                                              //this is the only difference between this & a normal skill check
                                            State.HasBeenMastered);
                                        if (trapRadius >= distanceToCenterOfDen)
                                        {
                                            //wuhoo, huge bonus odds!
                                            oddsOfCatchingSomething = Mathf.Clamp01(oddsOfCatchingSomething * Globals.TrappingOddsDistanceMultiplier);
                                        }
                                        else if (trapRadius >= distanceToDen)
                                        {
                                            //okay, no huge bonus but still cool
                                        }
                                        else
                                        {
                                            oddsOfCatchingSomething = 0f;
                                        }

                                        if (oddsOfCatchingSomething > 0f && UnityEngine.Random.value < oddsOfCatchingSomething)
                                        {
                                            Debug.Log("Caught something at creature den");
                                            if (den.TrapsSpawnCorpse)
                                            {
                                                float timeSinceDeath = UnityEngine.Random.Range(0f, (float)timeSinceSet);
                                                den.SpawnCreatureCorpse(trap.Owner.Position + Vector3.up, "Trap", timeSinceDeath);
                                            }
                                            //the trap will take care of itself
                                            trap.OnCatchTarget(State.NormalizedMasteryLevel);
                                            //we're done with this trap until it's triggered again
                                            Traps.RemoveAt(i);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    double waitUntil = Frontiers.WorldClock.AdjustedRealTime + 1f;
                    while (Frontiers.WorldClock.AdjustedRealTime < waitUntil)
                    {
                        yield return(null);
                    }
                }
                yield return(null);
            }
            mUpdatingTraps = false;
            yield break;
        }
Пример #20
0
 void ITrapFacade.UnregisterTrap(ITrap trap)
 {
     trap.Activated   -= HandleTrapActivation;
     trap.Deactivated -= HandleTrapDeactivation;
     _Traps.Remove(trap);
 }
Пример #21
0
 public static void TrapHitWall(ITrap trap, Rectangle block)
 {
     GetOffBlock(trap, block);
 }
Пример #22
0
 void Awake()
 {
     trap = GetComponent <ITrap>();
 }
Пример #23
0
 void ITrapFacade.RegisterTrap(ITrap trap)
 {
     _Traps.Add(trap);
     trap.Activated   += HandleTrapActivation;
     trap.Deactivated += HandleTrapDeactivation;
 }
Пример #24
0
 public void AddTrap(ITrap trap)
 {
     traps.Add(trap);
 }
Пример #25
0
 public void RemoveTrap(ITrap trap)
 {
     (traps as List <ITrap>).RemoveAll(x => x.Center == trap.Center);
 }
Пример #26
0
 public TrapCollidable(ITrap trap)
 {
     this.trap      = trap;
     DamageDisabled = true;
 }