Page 1 of 1

[committed] Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 12:40 pm
by Dre
I do many changes:

Mob command:
- Add: Commands "/mob trigger info" and "/mob trigger remove <id>" (Trigger's ID is given by "/mob trigger info")
- Change: Less call to List<T>'s indexer in FireAmbientSentence
- Bugfix: The sentence was escaped 2 times in "/mob trigger"
Others:
- Change: IPacketHandler.HandlePacket return void instead of an int (the value was never used).
- Change: Some use of optional parameters and refactoring in GameObject and PacketLib
- Change: Use of Dictionary<T>.TryGetValue instead of t/c in LootGeneratorTemplate
- Change: Use of C#4 compiler for scripts instead of C#3.5

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 12:54 pm
by Graveen
Thanks Dre. The optionnal parameters are interesting, they clearly could remove a lot of multi-prototyped methods.

Thanks for the use of v4 compiler for scripts, i clearly forgot to change it :)

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 1:00 pm
by Tolakram
Wait wait wait

public bool IsWithinRadius(GameObject obj, int radius, bool ignoreZ = false)

C# now supports this! Did I miss this! That makes me so happy.

Code: Select all
// now force a refresh of the mobs default loot template

if (isDefaultLootTemplateRefreshed == false)
- {
RefreshLootTemplate(mob.Name);
- }
I strongly disagree with this change. There is no reason to remove the braces and I added them for readability. :)

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 1:02 pm
by Graveen
This v4 of the compiler is unsupportable for VB's devs who got this syntaxic sugar for ages (or php ones) :D

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 1:05 pm
by Tolakram
One of the biggest gripes I had when switching from C++ to C# was the lack of default parameters. I used them heavily, probably too much, but I love them. :)

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 1:20 pm
by Graveen
The 3 main features i'm aware in C# 4 related to syntaxic sugar (see full list here: http://msdn.microsoft.com/en-us/library/bb383815.aspx )

- Optionnal parameters (we talked 'bout it) and Named arguments: you can call the params in any order of the following prototype:
MyMethod(int arg1, string arg2=string.Empty, bool arg3)
Code: Select all
MyMethod(arg3: true, arg2: 12);
- Something interesting for DOL is dynamic declaration: resolved at runtime, not at compilation time like var. This is generally used with reflection, to avoid the boring process of getting the type of the Methods. We could write without compilation error:
Code: Select all
dynamic dynamicDemoClassObj = Activator.CreateInstance(demoClassType);
dynamicDemoClassObj.Name = "Adil";
where we should previously write something like
Code: Select all
Assembly asmLib= Assembly.LoadFile(@"C:\temp\DemoClass\bin\Debug\DemoClass.dll");
Type demoClassType = asmLib.GetType("DemoClass.DemoClassLib");
object demoClassobj= Activator.CreateInstance(demoClassType);
PropertyInfo pInfo= demoClassType.GetProperty("Name");
pInfo.SetValue(demoClassobj, "Adil", null);

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 1:23 pm
by Dre
Code: Select all
// now force a refresh of the mobs default loot template

if (isDefaultLootTemplateRefreshed == false)
- {
RefreshLootTemplate(mob.Name);
- }
I strongly disagree with this change. There is no reason to remove the braces and I added them for readability. :)
Oh, it's just Resharper that propose me to remove them and sometimes, I accept... =)
One of the biggest gripes I had when switching from C++ to C# was the lack of default parameters. I used them heavily, probably too much, but I love them. :)
There are some problem in C#, if I have "public int Toto(int toto = 0)" and I want to use it in "Func<int> func = Toto;", this doesn't work...

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 1:51 pm
by Graveen
resharper does not like the inline braces for TCF.
There is enough here to start another religious developper war ! :mrgreen:

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 1:53 pm
by Tolakram
lol. MUST HAVE CURLY BRACES!

My argument is, as a manager, I've seen too many middling developers screw up when braces do not clearly denote blocks. I think dre is probably more skilled than I am at coding, but think of the children!

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 2:35 pm
by Dre
resharper does not like the inline braces for TCF.
There is enough here to start another religious developper war ! :mrgreen:
resharper have very bad default options:
- Use of var when it's possible (I'm agree with "var toto = new ..." but I'm not with "var toto = Method()"...)
- A realy bad one: It uses too many memory and cpu (don't use it on a laptop... ><)
- And many others

But Resharper have good features:
- Refactoring (with many options)
- Add autocompletion for dynamic's types
- Change "Find usage" by a better one
- Give many usefull warning (a good one: "Possible loss of fraction" when we have: "int toto = 5 / 3 * 4", toto = 4 because 5 / 3 = 1 in integer division, this can be fixed without double or float with "int toto = 5 * 4 / 3")
- Display note, warnings or errors in file
- And many others but many for theses features are added in VS2010

I don't know if SharpDevelop purpose theses features, I will test it =)

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 3:03 pm
by Graveen
#D propose some common refactoring ways, but generally related to code generation (override wizard, method extraction, class wizard with property generation, list overirde in a single clic, etc...) but not so deep than R# can do.

#D is rather to see like an interesting IDE for unit test integration, code coverage, builtin profiler, multi language support (in particular ironpython/ironruby/F#/C++ in addition of VB.NET and C#), WiX integration, SHFB integration, object graph visualizer, SVN or GIT direct integration, Built in report builder, embedded MSHelp 2 provided with windows 7 Sdk...

Right click on a method, or use contextual menu. #D lacks edit and continue, document outline in winforms, compact framework support, database browser, server explorer..., but after the fact the IDE is opensource, you have a really nice coherent set of tools without having to use VS plugins (no visual svn, no crystal reports, in example), interesting templates, and even an EDM Designer.

I don't talk about common things - class explorer, project browser, console support, conditionnal BPs, debug suite winform/wpf designer, ressource editor - which are commons.

Bah i could talk with you of #D for ages; i'd not convince ppl used to work with VS that it is a better tool (and it is obviously not), but i'm totally in phase with the tool :)

Re: Somes changes in "/mob" and GameServer

PostPosted: Thu Oct 28, 2010 4:04 pm
by Dre
lol. MUST HAVE CURLY BRACES!

My argument is, as a manager, I've seen too many middling developers screw up when braces do not clearly denote blocks. I think dre is probably more skilled than I am at coding, but think of the children!
I don't see your reply, I'm not agree with all...

I'm agree braces are needed with something like:
Code: Select all
byte value;
using(Stream inStr = File.Open("toto"))
if ((value = inStr.ReadByte()) != 0)
lock(_sync)
this.Value = value;
// Or
if (inStr.ReadByte() == 0 && inStr.ReadByte() == (int)eDummyEnum.DummyValue && inStr.ReadByte() == (int)eDummyEnum2.DummyValue2 &&
inStr.ReadByte() == 10)
Console.WriteLine("Hello");
// "inStr" can't be used after this code "inStr.Position = ??"
And this code, must be:
Code: Select all
byte value;
using(Stream inStr = File.Open("toto"))
{
if ((value = inStr.ReadByte()) != 0)
{
lock(_sync)
this.Value = value;
}
}
// And
byte byte1 = inStr.ReadByte(); // Read bytes before condition, we aren't lost in stream after the condition
byte byte2 = inStr.ReadByte();
byte byte3 = inStr.ReadByte();
byte byte4 = inStr.ReadByte();
if (byte1 == 0 && byte2 == (int)eDummyEnum.DummyValue && byte3 == (int)eDummyEnum2.DummyValue2 &&
byte4 == 10)
{ // Add braces, we cann't see (quickly) the condition and the scope without them
Console.WriteLine("Hello");
}
// inStr.Position = 4 in all cases
After, it's just a preference... I prefer to see "if (xxx)\n<code>;" than "if (xxx)\n{\n<code>\n}\n".

Re: Somes changes in "/mob" and GameServer

PostPosted: Fri Oct 29, 2010 12:42 am
by Tolakram
Too lazy to commit all these changes but I wanted the v4 change so I made it to the core with credit to Dre. :) I'll let Graveen do the rest and run his glorious refactor tool.

Re: [committed] Somes changes in "/mob" and GameServer

PostPosted: Fri Oct 29, 2010 1:54 pm
by Graveen
Accepted, thank you, soon in SVN

Dre, tu as un compte sourceforge ?!