Game


You are not connected. Please login or register

Share code lệnh Fly, Move, Run để dev phó bản

Go down  Message [Page 1 of 1]

Fenix

Fenix
Game Master
Game Master
Lệnh này cho bản R2.5, R2.7 và 3.0 (phải có Source)

Vào Source -> Game.Logic -> Phy -> Object -> Living.cs chép đoạn này.


Code:
public bool WalkTo(int x, int y, string action, int delay, string sAction, int speed)
        {
            return this.WalkTo(x, y, action, delay, sAction, speed, null);
        }

        public bool WalkTo(int x, int y, string action, int delay, string sAction, int speed, LivingCallBack callback)
        {
            if ((base.m_x != x) || (base.m_y != y))
            {
                if ((x < 0) || (x > base.m_map.Bound.Width))
                {
                    return false;
                }
                List<Point> path = new List<Point>();
                int num = base.m_x;
                int num2 = base.m_y;
                int direction = (x > num) ? 1 : -1;
                if (!(action == "fly"))
                {
                    while (((x - num) * direction) > 0)
                    {
                        Point item = base.m_map.FindNextWalkPoint(num, num2, direction, STEP_X, STEP_Y);
                        if (!(item != Point.Empty))
                        {
                            break;
                        }
                        path.Add(item);
                        num = item.X;
                        num2 = item.Y;
                    }
                }
                else
                {
                    Point point = new Point(x, y);
                    Point point2 = new Point(num - point.X, num2 - point.Y);
                    point = new Point(point.X + point2.X, y + point2.X);
                    point2 = new Point(x - point.X, x - point.Y);
                    bool flag1 = point != Point.Empty;
                    point = new Point(x, y);
                    path.Add(point);
                }
                if (path.Count > 0)
                {
                    this.m_game.AddAction(new LivingWalkAction(this, path, action, delay, speed, sAction, callback));
                    return true;
                }
            }
            return false;
        }  

Vào Source -> Game.Logic -> Actions tao LivingWalkAction.cs chép đoạn này.


Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Game.Logic.Phy.Object;
using System.Drawing;

namespace Game.Logic.Actions
{
    public class LivingWalkAction : BaseAction
    {
        private string m_action;
        
        private LivingCallBack m_callback;
        
        private int m_index;
        
        private bool m_isSent;
        
        private Living m_living;
        
        private List<Point> m_path;
        
        private string m_saction;
        
        private int m_speed;
    
        public LivingWalkAction(Living living, List<Point> path, string action, int delay, int speed, string sAction, LivingCallBack      callback) : base(delay, 0)
        {
            this.m_living = living;
            this.m_path = path;
            this.m_action = action;
            this.m_saction = sAction;
            this.m_isSent = false;
            this.m_index = 0;
            this.m_callback = callback;
            this.m_speed = speed;
        }

        protected override void ExecuteImp(BaseGame game, long tick)
        {
            if (!this.m_isSent)
            {
                this.m_isSent = true;
                Point point = this.m_path[this.m_path.Count - 1];
                Point point2 = this.m_path[this.m_path.Count - 1];
                game.SendLivingWalk(this.m_living, this.m_living.X, this.m_living.Y, point.X, point2.Y, this.m_action, this.m_speed, this.m_saction);
            }
            this.m_index++;
            if (this.m_index >= this.m_path.Count)
            {
                Point point3 = this.m_path[this.m_index - 1];
                if (point3.X > this.m_living.X)
                {
                    this.m_living.Direction = 1;
                }
                else
                {
                    this.m_living.Direction = -1;
                }
                Point point4 = this.m_path[this.m_index - 1];
                Point point5 = this.m_path[this.m_index - 1];
                this.m_living.SetXY(point4.X, point5.Y);
                if (this.m_callback != null)
                {
                    this.m_living.CallFuction(this.m_callback, 0);
                }
                base.Finish(tick);
            }
        }
    }
}  

Vào Source -> Game.Logic -> BaseGame.cs chép đoạn này.


Code:
internal void SendLivingWalk(Living living, int fromX, int fromY, int toX, int toY, string action, int speed, string sAction)
        {
            GSPacketIn pkg = new GSPacketIn((byte)ePackageType.GAME_CMD, living.Id);
            pkg.Parameter1 = living.Id;
            pkg.WriteByte((byte)eTankCmdType.LIVING_MOVETO);
            pkg.WriteInt(fromX);
            pkg.WriteInt(fromY);
            pkg.WriteInt(toX);
            pkg.WriteInt(toY);
            pkg.WriteInt(speed);
            pkg.WriteString(!string.IsNullOrEmpty(action) ? action : "");
            pkg.WriteString(sAction);
            SendToAll(pkg);
        }  

http://www.devgame.ga

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum