Example #1
0
 public void removeActor(CActor actor, bool nextCycle = false)
 {
     if (!nextCycle)
     {
         if (actor == root)
         {
             _killMe = true;
             enabled = false;
         }
         else
         {
             try
             {
                 actors.Remove(actor.name);
                 actor.component = null;
                 Map.CMapManager.removeFromActorRegistry(actor);
                 actor.Dispose();
             }
             catch (KeyNotFoundException) { }
         }
     }
     else
     {
         _removeThese.Add(actor);
     }
 }
Example #2
0
        public override void Update(GameTime gameTime)
        {
            root.update(gameTime);

            foreach (KeyValuePair <string, CActor> kvp in actors)
            {
                //first get messages from the commNet
                if (CMasterControl.commNet[(int)_address].Count() > 0)
                {
                    CActorPacket[] packetData = new CActorPacket[CMasterControl.commNet[(int)_address].Count()];
                    CMasterControl.commNet[(int)_address].CopyTo(packetData);

                    var group = from packets in packetData
                                where kvp.Key == packets.actor
                                select packets;

                    foreach (var result in group)
                    {
                        //pass the message to the actor
                        CActor temp = kvp.Value;
                        passMessage(ref temp, (uint)result.userEventID, result.getParams());
                        CMasterControl.commNet[(int)_address].Remove(result);
                    }
                }

                //update position relative to the root
                if (kvp.Value._followRoot)
                {
                    kvp.Value.position += root.distanceFromLastFrame;
                }

                //update
                kvp.Value.update(gameTime);
            }
        }
Example #3
0
 public CActorPacket(int userEvent, string actor, CActor sender, params object[] param)
 {
     _userEventID = userEvent;
     _actorName   = actor;
     _sender      = sender;
     _parameters  = new List <object>();
     if (param.Count() > 0)
     {
         _parameters.AddRange(param);
     }
 }
Example #4
0
        private void _disposeActors()
        {
            root.Dispose();
            root = null;

            foreach (KeyValuePair <string, CActor> kvp in actors)
            {
                kvp.Value.Dispose();
            }

            actors.Clear();
        }
Example #5
0
 public void addActor(CActor actor, String name)
 {
     //Add as root if no root is set
     if (root != null)
     {
         actors.Add(name, actor);
     }
     else
     {
         root = actor;
     }
     //Allow actor to access it's component
     actor.component = this;
 }
Example #6
0
        public void moveActorToNewComponent(CActor actor)
        {
            if (!actors.ContainsValue(actor))
            {
                throw new KotException.KotInvalidActorException("Actor does not belong to this component");
            }

            if (actor == root)
            {
                throw new KotException.KotInvalidActorException("Cannot move root actor to a new component");
            }

            actors.Remove(actor.name);
            Map.CMapManager.addComponent(actor, null);
        }
Example #7
0
        public object getProperty(string actorName, Map.EActorProperties property)
        {
            if (!actors.Keys.Contains(actorName))
            {
                if (root.name == actorName)
                {
                    return(propertySwitch(root, property));
                }
                return(null);
            }

            CActor actor = actors[actorName];

            return(propertySwitch(actor, property));
        }
Example #8
0
        protected void solidCollide(CActor collider, bool knockBack = false)
        {
            //Calculate How much to move to get out of collision moving towards last collisionless point
            Collision.CHitBox otherbox = collider.hitBox;

            //Calculate how far in we went
            float distx = (collider.position.X + otherbox.center.X) - (position.X + hitBox.center.X);

            distx = (float)Math.Sqrt(distx * distx);
            float disty = (position.Y + hitBox.center.Y) - (collider.position.Y + otherbox.center.Y);

            disty = (float)Math.Sqrt(disty * disty);

            float lenx = hitBox.halfWidth + otherbox.halfWidth;
            float leny = hitBox.halfHeight + otherbox.halfHeight;

            int px = 1;
            int py = 1;

            if (collider.position.X + otherbox.center.X < position.X + hitBox.center.X)
            {
                px = -1;
            }
            if (collider.position.Y + otherbox.center.Y < position.Y + hitBox.center.Y)
            {
                py = -1;
            }

            float penx = px * (distx - lenx);
            float peny = py * (disty - leny);
            //Resolve closest to previous position
            float diffx = (position.X + penx) - _oldPosition.X;

            diffx *= diffx;
            float diffy = (position.Y + peny) - _oldPosition.Y;

            diffy *= diffy;

            if (!knockBack)
            {
                _escapeCollide(diffx, diffy, penx, peny);
            }
            else
            {
                _knockBack(diffx, diffy, px, py);
            }
        }
Example #9
0
 public void removeActor(CActor actor)
 {
     if (actor.component == this)
     {
         //If we are removing the root, we need to add the next actor as root
         if (root == actor)
         {
             root = actors.GetEnumerator().Current.Value;
             actors.Remove(root.name);
             //This will fail if there are no more root, but in that case we can't realy do much, nor should that happen.
         }
         else
         {
             actor.component = null;
             actors.Remove(actor.name);
         }
     }
 }
Example #10
0
        private void _destroyActors(bool hardDelete = true)
        {
            root.remove();
            root = null;


            foreach (KeyValuePair <string, CActor> kvp in actors)
            {
                if (hardDelete)
                {
                    Map.CMapManager.removeFromActorRegistry(kvp.Value);
                }

                kvp.Value.remove();
            }
            actors.Clear();
            Map.CMapManager.removeComponent(this);
        }
Example #11
0
        private object propertySwitch(CActor actor, Map.EActorProperties property)
        {
            switch (property)
            {
            case Map.EActorProperties.POSITION:
                return(actor.position);

            case Map.EActorProperties.COMPONENT_ADDRESS:
                return(actor.componentAddress);

            case Map.EActorProperties.OLD_POSITION:
                return(actor.oldPosition);

            case Map.EActorProperties.DIRECTION:
                return(actor.direction);

            default:
                return(null);
            }
        }
Example #12
0
        private void _checkCommNet(string type, CActor actor)
        {
            if (CMasterControl.commNet[(int)_address].Count() > 0)
            {
                CActorPacket[] packetData = new CActorPacket[CMasterControl.commNet[(int)_address].Count()];
                CMasterControl.commNet[(int)_address].CopyTo(packetData);

                var group = from packets in packetData
                            where type == packets.actor
                            select packets;

                foreach (var result in group)
                {
                    //pass the message to the actor
                    CActor temp = actor;
                    passMessage(ref temp, result.sender, (uint)result.userEventID, result.getParams());
                    CMasterControl.commNet[(int)_address].Remove(result);
                }
            }
        }
Example #13
0
        public override void Update(GameTime gameTime)
        {
            if (root.killMe)
            {
                _destroyActors(_softDelete);
                enabled = false;
            }

            if (enabled)
            {
                //update the root's old position and then update the actor
                _checkCommNet(root.name, root);
                root.update(gameTime);
                //List<CActor> _actors = actors.Values.ToList();

                for (int i = 0; i < actors.Count; i++)
                {
                    CActor actor = actors.Values.ElementAt(i);
                    if (actor.killMe)
                    {
                        removeActor(actor, true);
                        continue;
                    }
                    //first get messages from the commNet
                    _checkCommNet(actor.name, actor);

                    //update
                    actor.update(gameTime);
                }
                //remove any actors that are to be removed
                for (int i = 0; i < _removeThese.Count(); i++)
                {
                    removeActor(_removeThese[i]);
                }

                _removeThese.Clear();
            }
        }
Example #14
0
 protected void _queueActorForRegistration(CActor actor)
 {
     _actorsToBeRegistered.Enqueue(actor);
 }
Example #15
0
 private void _dealForce(int force, CActor target)
 {
 }
Example #16
0
 public virtual void dealDamange(int damage, CActor target)
 {
     target._hp -= damage;
 }
Example #17
0
 private void passMessage(ref CActor actor, uint eventID, params string[] param)
 {
     actor.addFireTrigger(eventID);
     actor.userParams.AddRange(param);
 }
Example #18
0
 private void passMessage(ref CActor actor, CActor sender, uint eventID, params object[] param)
 {
     actor.addFireTrigger(eventID, sender);
     actor.userParams.AddRange(param);
 }
Example #19
0
 public virtual void collideExit(object sender, CActor collider)
 {
 }
Example #20
0
 public void addFireTrigger(uint userEvent, CActor sender)
 {
     _userEventsToFire.Add(userEvent, sender);
 }
Example #21
0
 private void passMessage(ref CActor actor, uint eventID, params string[] param)
 {
     actor.addFireTrigger(eventID);
     actor.userParams.AddRange(param);
 }