Exemplo n.º 1
0
        public virtual void StartClientEvent(ICombatActor actor, Hashtable additionalInfo)
        {
            Hashtable data = new Hashtable {
                { SkillProp.SKILL_ID, this.ID },
                { SkillProp.COOLDOWN, _cooldown },
                { SkillProp.ACTIVE_TIME, active_time },
                { SkillProp.SOURCE_ACTOR_ID, actor.Avatar.Id },
                { SkillProp.TARGET_ACTOR_ID, actor.GetTarget.TargetId },
                { SkillProp.ACTOR_TYPE, actor.Avatar.Type },
                { SkillProp.TARGET_TYPE, actor.GetTarget.Type },
                { SkillProp.ADDITIONAL_INFO, (additionalInfo != null) ? additionalInfo : new Hashtable() },
                { SkillProp.RETURN_CODE, (byte)ReturnCode.Ok }
            };

            SendParameters sendParameters = new SendParameters
            {
                Unreliable = true,
                ChannelId  = Settings.ItemEventChannel
            };

            UseSkillEventData evtInstance = new UseSkillEventData
            {
                Properties = data
            };

            EventData eventData = new EventData((byte)EventCode.UseSkill, evtInstance);
            var       message   = new ItemEventMessage(actor.Avatar, eventData, sendParameters);

            ((MmoItem)actor.Avatar).ReceiveEvent(eventData, sendParameters);
            actor.Avatar.EventChannel.Publish(message);
        }
        private OperationResponse ItemOperationSetProperties(Item item, SetProperties operation, SendParameters sendParameters, MmoActor actor)
        {
            MethodReturnValue result = this.CheckAccess(item, actor);

            if (result)
            {
                item.properties.SetProperties(operation.PropertiesSet, operation.PropertiesUnset);
                var eventInstance = new ItemPropertiesSet {
                    ItemId             = item.Id,
                    ItemType           = item.Type,
                    PropertiesRevision = item.properties.propertiesRevision,
                    PropertiesSet      = operation.PropertiesSet,
                    PropertiesUnset    = operation.PropertiesUnset
                };

                var eventData = new EventData((byte)EventCode.ItemPropertiesSet, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                // no response sent
                operation.OnComplete();
                return(null);
            }

            return(operation.GetOperationResponse(result));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Send to subscribers event about interactable state of activator
        /// </summary>
        /// <param name="interactable">Current interactable activator state</param>
        public void SendActivatorEvent(bool interactable)
        {
            if (!nebulaObject)
            {
                return;
            }

            var eventInstance = new ItemGeneric {
                ItemId          = nebulaObject.Id,
                ItemType        = nebulaObject.Type,
                CustomEventCode = (byte)CustomEventCode.Activator,
                EventData       = new Hashtable {
                    { (int)SPC.Interactable, interactable }
                }
            };
            SendParameters sendParameters = new SendParameters {
                ChannelId  = Settings.ItemEventChannel,
                Unreliable = false
            };
            var eventData = new EventData((byte)EventCode.ItemGeneric, eventInstance);

            var msg = new ItemEventMessage(nebulaObject as Item, eventData, sendParameters);

            (nebulaObject as Item).EventChannel.Publish(msg);
        }
Exemplo n.º 4
0
        private static void SpawnMobHelper(Mob newMob)
        {
            mobTable.Add(newMob.mobItem.Id, newMob);
            newMob.mobItem.World.ItemCache.AddItem(newMob.mobItem);
            newMob.mobItem.UpdateRegionSimple();

            GlobalVars.log.InfoFormat("adding bot to botman");
            // send event
            var eventInstance = new BotSpawn
            {
                ItemId   = newMob.mobItem.Id,
                Position = newMob.mobItem.Position,
                Rotation = newMob.mobItem.Rotation,
            };

            SendParameters sp = MmoActorOperationHandler.GetDefaultSP();
            //  sp.Unreliable = false;
            var eventData = new EventData((byte)EventCode.BotSpawn, eventInstance);
            var message   = new ItemEventMessage(newMob.mobItem, eventData, sp);

            newMob.mobItem.EventChannel.Publish(message);
            ((MmoActorOperationHandler)serverPeer.CurrentOperationHandler).AddItem(newMob.mobItem);
            //todo add bot to radar, just check that the world is the right one
            // ((World)this.World).Radar.AddItem(item, operation.Position);
        }
Exemplo n.º 5
0
        /// <summary>
        /// The publish update.
        /// </summary>
        /// <param name="item">
        /// The publisher.
        /// </param>
        /// <param name="position">
        /// The position.
        /// </param>
        /// <param name="unreliable">
        /// The unreliable.
        /// </param>
        private void PublishUpdate(Item item, float[] position, bool unreliable)
        {
            RadarUpdate updateEvent = GetUpdateEvent(item, position);
            IEventData  eventData   = new EventData((byte)EventCode.RadarUpdate, updateEvent);
            var         message     = new ItemEventMessage(item, eventData, new SendParameters {
                Unreliable = unreliable, ChannelId = Settings.RadarEventChannel
            });

            this.channel.Publish(message);
        }
Exemplo n.º 6
0
        protected override void OnDestroy()
        {
            var eventInstance = new ItemDestroyed {
                ItemId = this.Id, ItemType = this.Type
            };
            var eventData = new EventData((byte)EventCode.ItemDestroyed, eventInstance);
            var message   = new ItemEventMessage(this, eventData, new SendParameters {
                ChannelId = Settings.ItemEventChannel
            });

            this.EventChannel.Publish(message);
        }
Exemplo n.º 7
0
        protected override void OnDestroy()
        {
            //log.InfoFormat("destroy object of type {0}", (ItemType)Type);
            var eventInstance = new ItemDestroyed {
                ItemId = this.Id, ItemType = this.Type
            };
            var eventData = new EventData((byte)EventCode.ItemDestroyed, eventInstance);
            var message   = new ItemEventMessage(this, eventData, new SendParameters {
                ChannelId = Settings.ItemEventChannel
            });

            this.EventChannel.Publish(message);
            base.OnDestroy();
            this.Dispose(true);
        }
Exemplo n.º 8
0
        private void SendPropertiesEvent()
        {
            var inst = new ItemProperties {
                ItemId             = nebulaObject.Id,
                ItemType           = nebulaObject.Type,
                PropertiesRevision = nebulaObject.properties.propertiesRevision,
                PropertiesSet      = nebulaObject.properties.raw
            };
            var            evtData        = new EventData((byte)EventCode.ItemProperties, inst);
            SendParameters sendParameters = new SendParameters {
                ChannelId = Settings.ItemEventChannel
            };
            var message = new ItemEventMessage(nebulaObject as Item, evtData, sendParameters);

            (nebulaObject as Item).EventChannel.Publish(message);
        }
Exemplo n.º 9
0
        private OperationResponse ItemOperationMove(MmoItem item, Move operation, SendParameters sendParameters, MmoActor actor) {
            // should always be OK
            MethodReturnValue result = this.CheckAccess(item, actor);

            if (result) {
                // save previous for event
                float[] oldPosition = item.transform.position.ToArray();
                float[] oldRotation = item.transform.rotation.ToArray();

                // move
                item.transform.SetRotation(operation.Rotation);
                item.Move(operation.Position);

                float speed = 0f;
                var ship = item.GetComponent<PlayerShip>();
                var movalble = item.GetComponent<MovableObject>();
                if(ship) {
                    speed = movalble.speed;
                }

                // send event
                var eventInstance = new ItemMoved {
                    ItemId = item.Id,
                    ItemType = item.Type,
                    OldPosition = oldPosition,
                    Position = operation.Position,
                    Rotation = operation.Rotation,
                    OldRotation = oldRotation,
                    Speed = speed
                };

                var eventData = new EventData((byte)EventCode.ItemMoved, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                //I ADDED toMOVE AT POSITION
                //item.ReceiveEvent(eventData, sendParameters);

                // no response sent
                operation.OnComplete();
                return null;
            }

            return operation.GetOperationResponse(result);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Send to subscribers message about collecting asteroid
        /// </summary>
        /// <param name="containerType">Container(asteroid) type</param>
        /// <param name="containerId">Container(asteroid) ID</param>
        public void PublishStartAsteroidCollecting(byte containerType, string containerId)
        {
            Hashtable data = new Hashtable {
                { (int)SPC.ContainerType, containerType },
                { (int)SPC.ContainerId, containerId }
            };
            ItemGeneric eventInstance = new ItemGeneric {
                ItemId          = nebulaObject.Id,
                ItemType        = nebulaObject.Type,
                CustomEventCode = (byte)CustomEventCode.StartAsteroidCollecting,
                EventData       = data
            };
            SendParameters sendParameters = new SendParameters {
                Unreliable = false, ChannelId = Settings.ItemEventChannel
            };
            EventData        eventData = new EventData((byte)EventCode.ItemGeneric, eventInstance);
            ItemEventMessage message   = new ItemEventMessage(nebulaObject as Item, eventData, sendParameters);

            (nebulaObject as Item).EventChannel.Publish(message);
        }
Exemplo n.º 11
0
        /// <summary>
        /// when changed some property send it to others and self
        /// </summary>
        /// <param name="properties"></param>
        public void SendPropertyUpdate(Hashtable pps, bool onlyReceive = false)
        {
            if (nebulaObject.getItemType() != ItemType.Avatar)
            {
                return;
            }

            AddProps(pps);


            float time = Time.timeFromStartF;

            if (time > m_LastUpdateTime + 0.2f)
            {
                ItemPropertyUpdate eventInstance = new ItemPropertyUpdate {
                    itemId     = nebulaObject.Id,
                    itemType   = nebulaObject.Type,
                    properties = m_PropertyCache
                };
                SendParameters sendParameters = new SendParameters {
                    Unreliable = false, ChannelId = Settings.ItemEventChannel
                };
                EventData eventData = new EventData((byte)EventCode.ItemPropertyUpdate, eventInstance);
                var       message   = new ItemEventMessage(nebulaObject as Item, eventData, sendParameters);

                if (!onlyReceive)
                {
                    (nebulaObject as Item).EventChannel.Publish(message);
                }

                if (nebulaObject.IsPlayer())
                {
                    ReceiveEvent(eventData, sendParameters);
                }

                m_PropertyCache = new Hashtable();
                //log.InfoFormat("send property update... delta = {0}", time - m_LastUpdateTime);
                m_LastUpdateTime = time;
            }
        }
Exemplo n.º 12
0
        public void PublishMove(float[] fromPos, float[] fromRot, float[] toPos, float[] toRot, float speed)
        {
            if (nebulaObject)
            {
                var eventInstance = new ItemMoved {
                    ItemId      = nebulaObject.Id,
                    ItemType    = nebulaObject.Type,
                    OldPosition = fromPos,
                    Position    = toPos,
                    OldRotation = fromRot,
                    Rotation    = toRot,
                    Speed       = speed
                };

                var            eventData      = new EventData((byte)EventCode.ItemMoved, eventInstance);
                SendParameters sendParameters = new SendParameters {
                    ChannelId = Settings.ItemEventChannel, Unreliable = true
                };
                var message = new ItemEventMessage(nebulaObject as Item, eventData, sendParameters);
                (nebulaObject as Item).EventChannel.Publish(message);
            }
        }
Exemplo n.º 13
0
Arquivo: Mob.cs Projeto: geosohal/Mmo
        public void Regenerate(float elapsedSec)
        {
            if (hp >= GlobalVars.MotherHP)
            {
                return;
            }
            hpAccumulated += elapsedSec * HPregenPerSec;
            if (hpAccumulated > hpRegainAmount)
            {
                int hpToAdd = (int)hpAccumulated;
                hp           += hpToAdd;
                hpAccumulated = hpAccumulated - (float)Math.Floor(hpAccumulated);

                var eventInstance1 = new HpEvent
                {
                    ItemId   = this.mobItem.Id,
                    HpChange = -hpToAdd,
                };
                var eventData1 = new EventData((byte)EventCode.HpEvent, eventInstance1);
                var message1   = new ItemEventMessage(target.Avatar, eventData1, MmoActorOperationHandler.GetDefaultSP());
                mobItem.EventChannel.Publish(message1);
            }
        }
Exemplo n.º 14
0
        public void SendClientErrorEvent(ICombatActor actor, ReturnCode code, string reason)
        {
            Hashtable data = new Hashtable {
                { SkillProp.RETURN_CODE, (byte)code },
                { SkillProp.REASON_MESSAGE, reason }
            };
            SendParameters sendParameters = new SendParameters
            {
                Unreliable = true,
                ChannelId  = Settings.ItemEventChannel
            };

            UseSkillEventData evtInstance = new UseSkillEventData
            {
                Properties = data
            };

            EventData eventData = new EventData((byte)EventCode.UseSkill, evtInstance);
            var       message   = new ItemEventMessage(actor.Avatar, eventData, sendParameters);

            ((MmoItem)actor.Avatar).ReceiveEvent(eventData, sendParameters);
            actor.Avatar.EventChannel.Publish(message);
        }
Exemplo n.º 15
0
        private void SendEventData(EventReceiver receiver, EventData eventData, SendParameters sendParameters)
        {
            switch (receiver)
            {
            case EventReceiver.ItemOwner:
                ReceiveEvent(eventData, sendParameters);
                break;

            case EventReceiver.ItemSubscriber:
            {
                var msg = new ItemEventMessage(nebulaObject as Item, eventData, sendParameters);
                (nebulaObject as Item).EventChannel.Publish(msg);
            }
            break;

            case EventReceiver.OwnerAndSubscriber:
            {
                ReceiveEvent(eventData, sendParameters);
                var msg = new ItemEventMessage(nebulaObject as Item, eventData, sendParameters);
                (nebulaObject as Item).EventChannel.Publish(msg);
            }
            break;
            }
        }
Exemplo n.º 16
0
 /// <summary>
 ///   Sends the event to the client.
 /// </summary>
 /// <param name = "peer">
 ///   The client peer.
 /// </param>
 /// <param name = "message">
 ///   The message.
 /// </param>
 private static void RadarChannel_OnItemEventMessage(PeerBase peer, ItemEventMessage message)
 {
     // already in right fiber, we would use peer.SendEvent otherwise
     peer.SendEvent(message.EventData, message.SendParameters);
 }
Exemplo n.º 17
0
Arquivo: Mob.cs Projeto: geosohal/Mmo
        public void UpdatePosition(float elapsedSeconds, SendParameters sp)
        {
            if (mobItem.Disposed)
            {
                return;
            }
            Vector oldPosition = mobItem.Position;

            this.timeSinceVelUpdate -= elapsedSeconds;
            if (mobItem.wasBursted)
            {
                mobItem.secSinceBursted -= elapsedSeconds;
                if (mobItem.secSinceBursted <= 0)
                {
                    mobItem.wasBursted = false;
                }
            }

            if (state == BotState.Patroling)
            {
                float distToTargetSq = (currTargetPos - oldPosition).Len2;
                if (distToTargetSq < 800 || distToTargetSq > GlobalVars.MaxDistFromMotherSq)
                {
                    ChooseNewTargetPosAndSetVel();
                    //  GlobalVars.log.InfoFormat(mobItem.Id + "chose new velo");
                }
                if (mobItem.Velocity.Len2 > GlobalVars.maxShipVelSq + 1)
                {
                    mobItem.Velocity = mobItem.Velocity * GlobalVars.burstDampening;
                    SetVelToTarget();
                }
            }
            if (state == BotState.Chasing)
            {
                Vector diff        = target.Avatar.Position - mobItem.Position;
                float  distToTarg2 = diff.Len2;
                if (type == BotType.FastSwarm)
                {
                    currTargetPos = target.Avatar.Position;
                    SetVelToTarget();
                    // if bot is colliding with it's targetted player do damage
                    if (distToTarg2 < GlobalVars.swarmShipRadius2)
                    {
                        target.Hitpoints = target.Hitpoints - 1;

                        var eventInstance1 = new HpEvent
                        {
                            ItemId   = target.Avatar.Id,
                            HpChange = 1,
                        };
                        var eventData1 = new EventData((byte)EventCode.HpEvent, eventInstance1);
                        var message1   = new ItemEventMessage(target.Avatar, eventData1, sp);
                        target.Avatar.EventChannel.Publish(message1);
                    }
                }

                if (type == BotType.Swarm)
                {
                    if (distToTarg2 > GlobalVars.BotChasingStopDist2)
                    {
                        currTargetPos = target.Avatar.Position;
                        SetVelToTarget();
                    }
                    else
                    {
                        mobItem.Velocity = Vector.Zero;
                    }
                    if (timeTillReload > 0)
                    {
                        timeTillReload -= elapsedSeconds;
                    }

                    if (timeTillReload <= 0)    // bullet is ready
                    {
                        // check if target is within shoot range
                        if (distToTarg2 < GlobalVars.BotShotSight2)
                        {
                            timeTillReload   = GlobalVars.BotReloadTime;
                            mobItem.Rotation = diff / (float)Math.Sqrt(distToTarg2);
                            BotManager.MobFireBullet(mobItem);
                        }
                    }
                }
            }



            //mobItem.Move(oldPosition + mobItem.Velocity * elapsedSeconds);
            mobItem.SetPos(oldPosition + mobItem.Velocity * elapsedSeconds);
            mobItem.UpdateRegionSimple();


            if (GlobalVars.TrueTenPercent)
            {
                //    GlobalVars.log.InfoFormat("mob Pos " + oldPosition.ToString());
            }

            // send event
            var eventInstance = new ItemMoved
            {
                ItemId      = mobItem.Id,
                OldPosition = oldPosition,
                Position    = mobItem.Position,
                Rotation    = mobItem.Rotation, // not changing rotation
                OldRotation = mobItem.Rotation
            };
            var eventData = new EventData((byte)EventCode.ItemMoved, eventInstance);
            var message   = new ItemEventMessage(mobItem, eventData, sp);

            mobItem.EventChannel.Publish(message);
        }
Exemplo n.º 18
0
        /// <summary>
        ///   The set properties.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        /// <returns>
        ///   error code ok
        /// </returns>
        private OperationResponse ItemOperationSetProperties(Item item, SetProperties operation, SendParameters sendParameters)
        {
            MethodReturnValue result = this.CheckAccess(item);
            if (result)
            {
                item.SetProperties(operation.PropertiesSet, operation.PropertiesUnset);
                var eventInstance = new ItemPropertiesSet
                    {
                        ItemId = item.Id, 
                        ItemType = item.Type, 
                        PropertiesRevision = item.PropertiesRevision, 
                        PropertiesSet = operation.PropertiesSet, 
                        PropertiesUnset = operation.PropertiesUnset
                    };

                var eventData = new EventData((byte)EventCode.ItemPropertiesSet, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                // no response sent
                operation.OnComplete();
                return null;
            }

            return operation.GetOperationResponse(result);
        }
Exemplo n.º 19
0
 private void SubscribedItem_OnItemEvent(ItemEventMessage message)
 {
 }
Exemplo n.º 20
0
        public void PublishSkillUsed(EventReceiver receiver, NebulaObject target, PlayerSkill skill, bool success, string message, Hashtable result)
        {
            if (skill.IsEmpty)
            {
                return;
            }
            if (!(nebulaObject))
            {
                return;
            }

            if (false == nebulaObject.IsPlayer())
            {
                if (receiver == EventReceiver.OwnerAndSubscriber)
                {
                    receiver = EventReceiver.ItemSubscriber;
                }
                else if (receiver == EventReceiver.ItemOwner)
                {
                    return;
                }
            }

            skillUseIndex++;
            if (skillUseIndex == int.MaxValue)
            {
                skillUseIndex = 1;
            }
            Hashtable data = new Hashtable {
                { (int)SPC.IsOn, skill.isOn },
                { (int)SPC.Data, skill.data.GetInfo() },
                { (int)SPC.Source, nebulaObject.Id },
                { (int)SPC.SourceType, nebulaObject.Type },
                { (int)SPC.Target, target.Id },
                { (int)SPC.TargetType, target.Type },
                { (int)SPC.IsSuccess, success },
                { (int)SPC.Message, message },
                { (int)SPC.Info, result },
                { (int)SPC.Index, skillUseIndex }
            };
            SendParameters sendParameters = new SendParameters {
                Unreliable = false, ChannelId = Settings.ItemEventChannel
            };
            UseSkillEvent evt = new UseSkillEvent {
                Properties = data
            };
            EventData evtData = new EventData((byte)EventCode.UseSkill, evt);
            var       msg     = new ItemEventMessage(nebulaObject as Item, evtData, sendParameters);

            switch (receiver)
            {
            case EventReceiver.ItemOwner:
                ReceiveEvent(evtData, sendParameters);
                break;

            case EventReceiver.ItemSubscriber:
                (nebulaObject as Item).EventChannel.Publish(msg);
                break;

            case EventReceiver.OwnerAndSubscriber:
                ReceiveEvent(evtData, sendParameters);
                (nebulaObject as Item).EventChannel.Publish(msg);
                break;
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// The publish update.
 /// </summary>
 /// <param name="item">
 /// The publisher.
 /// </param>
 /// <param name="position">
 /// The position.
 /// </param>
 /// <param name="unreliable">
 /// The unreliable.
 /// </param>
 private void PublishUpdate(Item item, float[] position, bool unreliable)
 {
     RadarUpdate updateEvent = GetUpdateEvent(item, position);
     IEventData eventData = new EventData((byte)EventCode.RadarUpdate, updateEvent);
     var message = new ItemEventMessage(item, eventData, new SendParameters { Unreliable = unreliable, ChannelId = Settings.RadarEventChannel });
     this.channel.Publish(message);
 }
Exemplo n.º 22
0
        //; checks the ship item for collision with a potential projectile item, actor can be passed as
        // null if this ship is an npc. returns whether or not to delete the projectile
        public static bool CheckItemCollisionAgainstProjectile(Item ship, Item projectile, ref int hitPoints,
                                                               SendParameters sp, MmoActorOperationHandler actor, float shipRadiusSq, float shipRadius)
        {
            // if its a bullet and it's not my own bullet
            if ((byte)projectile.Type == (byte)ItemType.Bullet &&
                (actor == null || !actor.ContainsItem(projectile.Id)))
            {
                //Vector bulletPos = projectile.GetRewindedPos(Peer.RoundTripTime / 2);
                float distanceToBullet2 = (projectile.Position - ship.Position).Len2;
                //  GlobalVars.log.InfoFormat("checkin coll " + projectile.Id.ToString() + "dist: " + distanceToBullet2.ToString());
                if (distanceToBullet2 < shipRadiusSq)
                {
                    GlobalVars.log.InfoFormat(ship.Id + " COLLISION with: " +
                                              (ItemType)projectile.Type);
                    //if (removeList == null)
                    //    removeList = new List<Tuple<Item, Region>>();
                    //removeList.Add(new Tuple<Item, Region>(projectile, reg));   // set bullet to be removed

                    // sp.Unreliable = false;

                    var eventInstance = new HpEvent
                    {
                        ItemId   = ship.Id,
                        HpChange = GlobalVars.bulletDamage
                    };
                    var eventData = new EventData((byte)EventCode.HpEvent, eventInstance);
                    var message   = new ItemEventMessage(ship, eventData, sp);
                    ship.EventChannel.Publish(message);

                    hitPoints -= GlobalVars.bulletDamage;
                    if (hitPoints < 0)
                    {
                        // send itemdestroyed message for player's ship item
                    }
                    ((Bullet)projectile).SetDead();
                    //  projectile.SetPos(new Vector(-60000, -60000));
                    // projectile.UpdateRegionSimple();
                    return(true);
                }
            }
            else if ((byte)projectile.Type == (byte)ItemType.Bomb)
            {
                if (actor != null && actor.isSaberOut)
                {
                    Vector saberstartPt = new Vector();
                    Vector saberendPt   = new Vector();
                    saberstartPt = ship.Position + ship.Rotation * GlobalVars.saberStart;
                    saberendPt   = ship.Position + ship.Rotation * GlobalVars.saberLength;
                    Vector offset = new Vector();
                    if (MathHelper.Intersects(saberstartPt, saberendPt, projectile.Position, shipRadiusSq,
                                              ref offset, shipRadius, null, true))
                    {
                        GlobalVars.log.InfoFormat("saber collide with a bomb");

                        projectile.SetPos(projectile.Position + offset * 2.1f); // move over instantly to uncollided position

                        // set bomb velocity using 'collision impact' with saber
                        projectile.Velocity = projectile.Velocity + (offset / offset.Len) * ship.GetCumulativeDotProducts(8) * 90f;
                    }
                }
                // if this is not my bomb, check if i collide with it
                if ((actor != null && !actor.ContainsItem(projectile.Id)) || actor == null)
                {
                    Vector difference      = (projectile.Position - ship.Position);
                    float  distanceToBomb2 = difference.Len2;
                    if (distanceToBomb2 < (shipRadiusSq + GlobalVars.bombBallRadius2))
                    {
                        GlobalVars.log.InfoFormat("player + " + ship.Id.Substring(0, 3) + " collision with: " +
                                                  projectile.Id.ToString());
                        //if (removeList == null)
                        //    removeList = new List<Tuple<Item, Region>>();
                        //removeList.Add(new Tuple<Item, Region>(projectile, reg));   // set bomb to be removed

                        float t = (GlobalVars.bombRadius2 - distanceToBomb2) / GlobalVars.bombRadius2;
                        int   damageToPlayer = (int)Math.Floor(t * GlobalVars.bombDmg);
                        hitPoints -= damageToPlayer;

                        //   sp.Unreliable = false;

                        var eventInstance = new HpEvent
                        {
                            ItemId   = ship.Id,
                            HpChange = damageToPlayer,
                        };
                        var eventData = new EventData((byte)EventCode.HpEvent, eventInstance);
                        var message   = new ItemEventMessage(ship, eventData, sp);
                        ship.EventChannel.Publish(message);

                        float force = GlobalVars.bombForce * t;
                        difference           = difference / (float)Math.Sqrt(distanceToBomb2);
                        ship.wasBursted      = true;
                        ship.secSinceBursted = GlobalVars.timeForBurstToLast;
                        ship.Velocity        = ship.Velocity + difference * force;

                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 23
0
        /// <summary>
        ///   The operation raise generic event.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        /// <returns>
        ///   Ok or ItemNotFound
        /// </returns>
        private static OperationResponse ItemOperationRaiseGenericEvent(Item item, RaiseGenericEvent operation, SendParameters sendParameters)
        {
            if (item.Disposed)
            {
                return operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound");
            }

            var eventInstance = new ItemGeneric
                {
                   ItemId = item.Id, ItemType = item.Type, CustomEventCode = operation.CustomEventCode, EventData = operation.EventData 
                };

            var eventData = new EventData((byte)EventCode.ItemGeneric, eventInstance);
            sendParameters.Unreliable = (Reliability)operation.EventReliability == Reliability.Unreliable;
            sendParameters.ChannelId = Settings.ItemEventChannel;
            switch (operation.EventReceiver)
            {
                case (byte)EventReceiver.ItemOwner:
                    {
                        if (((IMmoItem)item).ReceiveEvent(eventData, sendParameters) == false)
                        {
                            string debugMessage = string.Format("Target item {0}/{1} could not receive event", item.Type, item.Id);
                            return operation.GetOperationResponse((int)ReturnCode.InvalidOperation, debugMessage);
                        }

                        break;
                    }

                case (byte)EventReceiver.ItemSubscriber:
                    {
                        var message = new ItemEventMessage(item, eventData, sendParameters);
                        item.EventChannel.Publish(message);
                        break;
                    }

                default:
                    {
                        return operation.GetOperationResponse((int)ReturnCode.ParameterOutOfRange, "Invalid EventReceiver " + operation.EventReceiver);
                    }
            }

            // no response
            operation.OnComplete();
            return null;
        }
Exemplo n.º 24
0
 /// <summary>
 ///   The subscribed item event.
 /// </summary>
 /// <param name = "message">
 ///   The message.
 /// </param>
 private void SubscribedItem_OnItemEvent(ItemEventMessage message)
 {
     ItemEventMessage.CounterEventReceive.Increment();
     this.peer.SendEvent(message.EventData, message.SendParameters);
 }
        private static OperationResponse ItemOperationRaiseGenericEvent(Item item, RaiseGenericEvent operation, SendParameters sendParameters)
        {
            try {
                if (item.Disposed)
                {
                    return(operation.GetOperationResponse((int)ReturnCode.ItemNotFound, "ItemNotFound"));
                }

                var eventInstance = new ItemGeneric {
                    ItemId          = item.Id,
                    ItemType        = item.Type,
                    CustomEventCode = operation.CustomEventCode,
                    EventData       = operation.EventData,
                };

                var eventData = new EventData((byte)EventCode.ItemGeneric, eventInstance);
                sendParameters.Unreliable = (Reliability)operation.EventReliability == Reliability.Unreliable;
                sendParameters.ChannelId  = Settings.ItemEventChannel;



                //switch ((CustomEventCode)operation.CustomEventCode) {
                //    case CustomEventCode.Fire:
                //        {
                //            Hashtable hashSource = eventInstance.EventData as Hashtable;
                //            //ShotType shotType = (ShotType)hashSource.Value<byte>((int)SPC.ShotType, (byte)ShotType.Light);
                //            WeaponHitInfo hit;
                //            Hashtable shotInfo = item.GetComponent<BaseWeapon>().Fire(out hit);
                //            item.GetComponent<MmoMessageComponent>().SendShot(EventReceiver.OwnerAndSubscriber, shotInfo);


                //            if (hit.hitAllowed && !hit.IsWeaponBlocked && hit.isHitted) {
                //                var damagable = item.GetComponent<ShipBasedDamagableObject>();
                //                var bonus = item.GetComponent<PlayerBonuses>();
                //            }
                //        }

                //        break;
                //}

                if ((CustomEventCode)operation.CustomEventCode != CustomEventCode.Fire)
                {
                    switch (operation.EventReceiver)
                    {
                    case (byte)EventReceiver.ItemOwner:
                    {
                        if (((IMmoItem)item).ReceiveEvent(eventData, sendParameters) == false)
                        {
                            string debugMessage = string.Format("Target item {0}/{1} could not receive event", item.Type, item.Id);
                            operation.OnComplete();
                            return(operation.GetOperationResponse((int)ReturnCode.InvalidOperation, debugMessage));
                        }

                        break;
                    }

                    case (byte)EventReceiver.ItemSubscriber:
                    {
                        var message = new ItemEventMessage(item, eventData, sendParameters);
                        item.EventChannel.Publish(message);
                        break;
                    }

                    case (byte)EventReceiver.OwnerAndSubscriber:
                    {
                        ((IMmoItem)item).ReceiveEvent(eventData, sendParameters);
                        var message = new ItemEventMessage(item, eventData, sendParameters);
                        item.EventChannel.Publish(message);
                        break;
                    }

                    default:
                    {
                        operation.OnComplete();
                        return(operation.GetOperationResponse((int)ReturnCode.ParameterOutOfRange, "Invalid EventReceiver " + operation.EventReceiver));
                    }
                    }
                }

                // no response

                return(null);
            } catch (Exception ex) {
                log.Error(ex);
            }
            operation.OnComplete();
            return(null);
        }
Exemplo n.º 26
0
 /// <summary>
 ///   Publishes event <see cref = "ItemDestroyed" /> in the <see cref = "Item.EventChannel" />.
 /// </summary>
 protected override void OnDestroy()
 {
     var eventInstance = new ItemDestroyed { ItemId = this.Id, ItemType = this.Type };
     var eventData = new EventData((byte)EventCode.ItemDestroyed, eventInstance);
     var message = new ItemEventMessage(this, eventData, new SendParameters { ChannelId = Settings.ItemEventChannel });
     this.EventChannel.Publish(message);
 }
Exemplo n.º 27
0
        /// <summary>
        ///   The move operation.
        /// </summary>
        /// <param name = "item">
        ///   The mmo item.
        /// </param>
        /// <param name = "operation">
        ///   The operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        /// <returns>
        ///   error code ok
        /// </returns>
        private OperationResponse ItemOperationMove(MmoItem item, Move operation, SendParameters sendParameters)
        {
            // should always be OK
            MethodReturnValue result = this.CheckAccess(item);
            if (result)
            {
                // save previous for event
                float[] oldPosition = item.Coordinate;
                float[] oldRotation = item.Rotation;

                // move
                item.Rotation = operation.Rotation;
                item.Move(operation.Position);

                // send event
                var eventInstance = new ItemMoved
                    {
                        ItemId = item.Id, 
                        ItemType = item.Type, 
                        OldPosition = oldPosition, 
                        Position = operation.Position, 
                        Rotation = operation.Rotation, 
                        OldRotation = oldRotation
                    };

                var eventData = new EventData((byte)EventCode.ItemMoved, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                // no response sent
                operation.OnComplete();
                return null;
            }

            return operation.GetOperationResponse(result);
        }